Skip to content

Latest commit

 

History

History
164 lines (156 loc) · 18.9 KB

kmr.Utils.new.md

File metadata and controls

164 lines (156 loc) · 18.9 KB

Utils

Utility methods

To invoke some utility method just call to Utils.UTIL_NAME(UTIL_PARAMS) or U.UTIL_NAME(UTIL_PARAMS), like so

    if Utils.InRangeI(x,0,5) then //Check x is in range of [0;5]
      ...

or, in short form

    if U.InRangeI(x,0,5) then //Check x is in range of [0;5]
      ...

Other scripts functions:

Dynamic scripts usefull info:



Ver
sion
Utility function
description
Parameters
and types
Returns
7000+ AbsI
Returns absolute value of specified integer
aValue: Integer; Integer
7000+ AbsS
Returns absolute value of specified single number
aValue: Single; Single
7000+ ArrayElementCount
Checks how many times specified string comes in requested array
aElement: AnsiString;
aArray: array of String;
Integer
7000+ ArrayElementCountB
Checks how many times specified boolean comes in requested array
aElement: Boolean;
aArray: array of Boolean;
Integer
7000+ ArrayElementCountI
Checks how many times specified integer comes in requested array
aElement: Integer;
aArray: array of Integer;
Integer
7000+ ArrayElementCountS
Checks how many times specified single comes in requested array
aElement: Single;
aArray: array of Single;
Integer
7000+ ArrayHasElement
Checks whether requested array has specified string
aElement: AnsiString;
aArray: array of String;
Boolean
7000+ ArrayHasElementB
Checks whether requested array has specified boolean
aElement: Boolean;
aArray: array of Boolean;
Boolean
7000+ ArrayHasElementI
Checks whether requested array has specified integer
aElement: Integer;
aArray: array of Integer;
Boolean
7000+ ArrayHasElementS
Checks whether requested array has specified single number
aElement: Single;
aArray: array of Single;
Boolean
7000+ ArrayRemoveIndexI
Removes element on specified index in specified array of integer.
Integer array should be declared as TIntegerArray instead of array of integer.
aIndex: Integer;
aArray: TIntegerArray;
TIntegerArray
7000+ ArrayRemoveIndexS
Removes element on specified index in specified array of string.
String array should be declared as TAnsiStringArray instead of array of AnsiString.
aIndex: Integer;
aArray: TAnsiStringArray;
TAnsiStringArray
7000+ BoolToStr
Return string representation of Boolean value: 'True' or 'False'
aBool: Boolean; AnsiString
7000+ CeilTo
Rounds specified single number aValue to nearest multiple of specified base aBase. Rounding up.
F.e. CeilTo(11.7, 5) = 15 while CeilTo(-11.7, 5) = -10
aValue: Single;
aBase: Integer;
Integer
10940 ColorBrightness
Get Color Brightness from HEX BGR color
aHexColor: string; Single // Color Brightness OR -1 if aHexColor not equal to HEX BGR
11750 CompareString
Compares Str1 to Str2, with case-sensitivity.
Str1: string;
Str2: string;
Integer // The return value is less than 0 if Str1 is less than Str2, 0 if Str1 equals Str2, or greater than 0 if Str1 is greater than Str2.
11750 CompareText
Compares Str1 to Str2, without case-sensitivity.
Str1: string;
Str2: string;
Integer // The return value is less than 0 if Str1 is less than Str2, 0 if Str1 equals Str2, or greater than 0 if Str1 is greater than Str2.
11750 CopyString
Creates a copy of part of a string
The first character of a string has index = 1.
Up to Count characters are copied from the Index of the Str string to the returned string.
Less than Count characters will be copied, if the end of the Str string is encountered before Count characters.
Str: string;
Index: Integer;
Count: Integer;
String // Copy of part of a Str string
11750 DeleteString
Deletes up to Count characters from the Str string starting from position Index
The first character of a string has index = 1.
If the Index is before the first, or after the last character of Str, then no characters are deleted
No error is produced if Count exceeds the remaining character count of Str.
var Str: string;
Index: Integer;
Count: Integer;
7000+ EnsureRangeI
Returns the closest to aValue integer that is in interval [aMin..aMax]
aValue: Integer;
aMin, aMax: Integer;
Integer
7000+ EnsureRangeS
Returns the closest to aValue single number that is in interval [aMin..aMax]
aValue: Single;
aMin, aMax: Single;
Single
7000+ FloorTo
Rounds specified single number aValue to nearest multiple of specified base aBase. Rounding down.
F.e. FloorTo(11.7, 5) = 10 while FloorTo(-11.7, 5) = -15
aValue: Single;
aBase: Integer;
Integer
7000+ Format
Wrapper for pascal Format function
Formats aFormatting string with specified aData array of parameters
aFormatting: string;
aData: array of const;
string
11000 FormatFloat
Wrapper for pascal FormatFloat function
Formats aValue with specified aFormat
aFormat: string;
aValue: Single;
string
7000+ IfThen
Checks condition aBool and returns aTrue/aFalse string depending on check result
aBool: Boolean;
aTrue: AnsiString;
aFalse: AnsiString;
AnsiString
7000+ IfThenI
Checks condition aBool and returns aTrue/aFalse integer depending on check result
aBool: Boolean;
aTrue: Integer;
aFalse: Integer;
Integer
7000+ IfThenS
Checks condition aBool and returns aTrue/aFalse single number depending on check result
aBool: Boolean;
aTrue: Single;
aFalse: Single;
Single
7000+ InAreaI
2D variant of InRange, can be used for unit locs checks
aX, aY: Integer;
aXMin: Integer;
aYMin: Integer;
aXMax: Integer;
aYMax: Integer;
Boolean
7000+ InAreaS
2D variant of InRange
aX, aY: Single;
aXMin: Single;
aYMin: Single;
aXMax: Single;
aYMax: Single;
Boolean
7000+ InRangeI
Checks whether specified aValue is in interval [aMin..aMax]
aValue: Integer;
aMin, aMax: Integer;
Boolean
7000+ InRangeS
Checks whether specified aValue is in interval [aMin..aMax]
aValue: Single;
aMin, aMax: Single;
Boolean
11750 InsertString
Inserts one string, Source into another string, Target at the given position Index.
The first character of a string has index = 1.
The Target string characters from the Index character are moved right to make way for the Source string.
The length of Target string is now the sum of the length of the two strings.
To insert into the start of Target, set Index to 1 or less.
To append to the end of Target, set Index after the last character of Target.
Source: string;
var Target: string;
Index: Integer;
7000+ KMPoint
Returns point record with specified coordinates
X, Y: Integer; TKMPoint
15000 Ln
Returns the natural logarithm of X
X: Extended; Extended
15000 Log10
Returns log of X for a base of 10
X: Extended; Extended
15000 Log2
Returns log of X for a base of 2
X: Extended; Extended
15000 LogN
Returns log of X for a specified base
Base: Extended;
X: Extended;
Extended
11750 LowerCase
Changes upper case characters in a string Str to lower case
Str: string; String
7000+ MaxI
Returns max number of two specified
A, B: Integer; Integer
7000+ MaxInArrayI
Returns max number of array elements
aArray: array of Integer; Integer
7000+ MaxInArrayS
Returns max number of array elements
aArray: array of Single; Single
7000+ MaxS
Returns max number of two specified
A, B: Single; Single
7000+ MinI
Returns min number of two specified
A, B: Integer; Integer
7000+ MinInArrayI
Returns min number of array elements
aArray: array of Integer; Integer
7000+ MinInArrayS
Returns min number of array elements
aArray: array of Single; Single
7000+ MinS
Returns min number of two specified
A, B: Single; Single
11750 MoveString
Copy data from a Source to a Destination
Count characters are copied from storage referenced by Source and written to Destination
It can be used to take a copy of a substring from one string and overlay it on top of part of another string.
Source: string;
var Destination: string;
Count: Integer;
11750 Pos
Searches for a substring, SubStr, in a string, Str.
Returns an integer value that is the index of the first character of SubStr within Str.
Function is case-sensitive.
If SubStr is not found, Result = 0
SubStr: string;
Str: string;
Integer
7000+ Power
Exponentation, base 'Base' raised to power 'Exp'.
F.e. Power(3, 2) = 3^2 = 9
Returns base "Base" raised to power "Exp"
aBase: Extended;
aExp: Extended;
Extended
11000 RandomRangeI
Generates a random number in requested range aFrom..aTo (inclusive)
aFrom: Integer;
aTo: Integer;
Integer
10940 RGBDecToBGRHex
Converts RGB to HEX BGR color
Example
VAR := RGBDecToBGRHex(255, 255, 0);
The result of the VAR will be 00FFFF
aR: Byte;
aG: Byte;
aB: Byte;
AnsiString // HEX BGR Color
10940 RGBToBGRHex
Converts HEX RGB to HEX BGR color
Example
VAR := RGBToBGRHex('#FFFF00');
The result of the VAR will be 00FFFF
aHexColor: string; AnsiString // HEX BGR Color or '' if aHexColor not equal to HEX RGB
12400+ RoundTo
Rounds specified single number aValue to nearest multiple of specified base aBase. Rounding to the nearest integer.
If the number is exactly midway between two integers, then it rounds towards the even one (multiplied on aBase).
F.e. RoundTo(11.7, 5) = 10 while RoundTo(-11.7, 5) = -10
RoundTo(12.5, 5) = 10 while RoundTo(17.5, 5) = 20
aValue: Single;
aBase: Integer;
Integer
7000+ Sqr
Returns A^2 = A*A
A: Extended; Extended
11750 StringReplace
Replaces the first or all occurences of a substring OldPattern in Str string with NewPattern according to additional settings
The changed string is returned as Result
The settings may be none, one, or both of these values:
Str: string;
OldPattern: string;
NewPattern: string;
aReplaceAll: Boolean; // Change all occurrences
aIgnoreCase: Boolean; // Ignore case when searching
String
7000+ SumI
Returns sum of the elements of requested array
aArray: array of Integer; Integer
7000+ SumS
Returns sum of the elements of requested array
aArray: array of Single; Single
7000+ TimeToString
Converts game ticks count into string: HH:MM:SS
Can be used for scripted timers
aTicks: Integer; AnsiString
10940 TimeToTick
Converts Time in game ticks
aHours: Integer;
aMinutes: Integer;
aSeconds: Integer;
Cardinal // game ticks
11750 Trim
Removes blank and control characters (such as line feed) from the start and end of a string.
Str: string; String
11750 TrimLeft
Removes blank and control characters (such as line feed) from the start of a string.
Str: string; String
11750 TrimRight
Removes blank and control characters (such as line feed) from the end of a string.
Str: string; String
12400+ TruncTo
Rounds specified single number aValue to nearest multiple of specified base aBase. Rounding to zero.
F.e. TruncTo(11.7, 5) = 10 while TruncTo(-11.7, 5) = -10
aValue: Single;
aBase: Integer;
Integer
11750 UpperCase
Changes lower case characters in a string Str to upper case
Str: string; String