Documentation › Modules › Basic.em
File: Basic.em
Functions for converting and manipulating number, character, and string values.
File Constants
const TRIM_LEFT := 0x1; // Trim whitespace from Left of string. const TRIM_RIGHT := 0x2; // Trim whitespace from Right of string. const TRIM_BOTH := 0x3; // Trim whitespace from Left and Right of string. // TypeOfInt() constants const OT_UNKNOWN := 0; const OT_UNINIT := 1; const OT_STRING := 2; const OT_LONG := 3; const OT_DOUBLE := 4; const OT_ARRAY := 5; const OT_APPLICPTR := 6; const OT_APPLICOBJ := 7; const OT_ERROR := 8; const OT_DICTIONARY := 9; const OT_STRUCT := 10; const OT_PACKET := 11; const OT_BINARYFILE := 12; const OT_XMLFILE := 13; const OT_XMLNODE := 14; const OT_XMLATTRIBUTES := 15; const OT_POLCOREREF := 16; const OT_ACCOUNTREF := 17; const OT_CONFIGFILEREF := 18; const OT_CONFIGELEMREF := 19; const OT_DATAFILEREF := 20; const OT_DATAELEMREF := 21; const OT_GUILDREF := 22; const OT_PARTYREF := 23; const OT_BOUNDINGBOX := 24; const OT_DEBUGCONTEXT := 25; const OT_SCRIPTEXREF := 26; const OT_PACKAGE := 27; const OT_MENUREF := 28; const OT_MOBILEREF := 29; const OT_OFFLINEMOBILEREF := 30; const OT_ITEMREF := 31; const OT_BOATREF := 32; const OT_MULTIREF := 33; const OT_CLIENTREF := 34; // Only applicable if SQL is active and compiled. const OT_SQLCONN := 35; const OT_SQLRESULT := 36; const OT_SQLROW := 37; const OT_BOOLEAN := 38; const OT_FUNCOBJECT := 39; const OT_EXPORTEDSCRIPT := 40; const OT_STORAGEAREA := 41; const OT_CLASSINSTANCEREF := 42; const OT_REGEXP := 43;
Bin( number )#
Parameters
| number | The number to convert |
Explanation
Returns the binary coded value of 'number'
Return values
A binary coded number
Boolean( number )#
Parameters
| number | 1/0 |
Explanation
Converts a number to an boolean value.
Return values
Returns an Boolean object.
CAsc( str )#
Parameters
| str | String to convert |
Explanation
Converts the first character of string to an ASCII code
Return values
ASCII code
CAscZ(str, nullterm := 0 )#
Parameters
| str | String to convert |
| nullterm | If true, adds a 0x00 to the end of the array |
Explanation
Converts the string to an array of the character's ASCII codes
Return values
Array of ASCII values
CChr( number )#
Parameters
| number | Integer to convert |
Explanation
Converts an ASCII value to a string consisting of one character.
Return values
A character
CChrZ(intarray, break_at_first_null := 0 )#
Parameters
| intarray | Array of ASCII values |
| break_at_first_null | If true, stops when 0x00 found |
Explanation
Converts an array of ASCII values to a string
Return values
A string
CDbl( expr )#
Parameters
| expr | A variable Int or String |
Explanation
Converts a string or int to a real. Only strings containing digits and '.' will return a predicatable result.
Ints will be expanded.
Return values
A Real
CInt( expr )#
Parameters
| expr | A variable Real or String |
Explanation
Converts a string or real to an integer. Only strings containing digits and '.' will return a predicatable
result. Doubles will be truncated.
Return values
An Int
CStr( expr )#
Parameters
| expr | A variable Int or Real |
Explanation
Converts a real or int to a string.
Return values
A String
Compare(str1, str2, pos1_start:=0, pos1_end:=0, pos2_start:=0, pos2_end:=0 )#
Parameters
| str1 | First string to compare |
| str2 | Second string to compare |
| pos1_start | The index to start from first string |
| pos1_end | The index to end from first string |
| pos2_start | The index to start from second string |
| pos2_end | The index to end from second string |
Explanation
Can be used in 3 overloaded ways. Returns 1 on compare success.
Compare(string1, string2) Compare(string1, string2, string1_index, string1_length) Compare(string1, string2, string1_index, string1_length, string2_index, string2_length)Index is a starting position to begin the compare in the string, and length is the length to compare from the index. When using the 3rd method, you can compare substrings in both strings instead of just the substring of string1 to entire string2.
Return values
1 on compare success/0
Errors
- "Index must not be negative for param 1"
- "Index out of range for param 1"
- "Index must not be negative for param 2"
- "Index out of range for param 2"
- "Length out of range for param 1"
- "Length must not be negative for param 1"
- "Length out of range for param 2"
- "Length must not be negative for param 2"
DecodeBase64( str )#
Parameters
| str | a string |
Explanation
Takes a base64 encoded string and converts it back to standard.
Return values
A String
EncodeBase64( str )#
Parameters
| str | a string |
Explanation
Returns a base64 encoded string string.
Return values
A String
Find(str, search, start )#
Parameters
| str | The string to search in |
| search | The string to search for |
| start | The index to start searching at |
Explanation
Returns the index of the first occurance of 'search' after 'start' within 'string'
Return values
An int
Hex( number )#
Parameters
| number | The number to convert |
Explanation
Returns the hexidecimal value of 'number'
Return values
A hexidecimal
Len( str_or_array )#
Parameters
| str_or_array | A string or array |
Explanation
For strings, returns string length. For arrays, returns number of elements. Does not work for structs or dictionaries, use .size() for those.
Return values
An Int
Lower( str )#
Parameters
| str | A string to convert |
Explanation
Converts 'string' to lowercase (doesn't work with high-ascii characters or unicode)
Return values
A string
Pack( expr )#
Parameters
| expr | An object to pack |
Explanation
Packs a variable into POL's packed data string format. Note that object references CANNOT be saved with the world, but may be passed to other running scripts, or with an event.
Return values
A string
PackJSON( expr, prettify )#
Parameters
| expr | An object to pack |
| prettify | If true, prettify the output string |
Explanation
Returns a JSON-serialization of the object to pack. If `prettify` is true, the output string will be indented with new lines.
The following conversions are done:
eScript -> JSON
double -> number
int -> number
string -> string
array -> array
struct -> object
dict -> object
bool -> bool
everything else -> null
Return values
string
RegExp(pattern, flags := "" )#
Parameters
| pattern | The text of the regular expression |
| flags | A string that contains the flags to add. Supported flags: 'u' for Unicode support; 'i' for case-insensitive matching; 'm' for treating multiline input strings as multiple lines (ie. ^ and $ will change from matching at only the start or end of the entire string to the start or end of any line within the string; 'g' for a global pattern, affecting how String methods (eg. 'match' and 'replace') behave. |
Explanation
Creates a new regular expression.
Return values
A RegExp object
Errors
- "Invalid flag character"
- "Invalid regular expression"
SizeOf( obj )#
Parameters
| obj | Any object |
Explanation
Returns an estimate of the memory used in bytes.
Return values
An int
SplitWords( str, delimiter := " ", max_split := -1 )#
Parameters
| str | The string to split |
| delimiter | The delimiter to use |
| max_split | Number of max splits. -1 = unlimited |
Explanation
Returns an array of words contained in 'string'. Words are separated by the delimiter.
Return values
An array
StrReplace(str, to_replace, replace_with )#
Parameters
| str | The string to modify |
| to_replace | The string to replace |
| replace_with | The string to replace with |
Explanation
Replace all instances of to_replace in the string with replace_with.
Return values
A String
SubStr(str, start, length )#
Parameters
| str | The string to search within |
| start | The index to start getting the substring from |
| length | The length of the substring |
Explanation
Returns the substring of 'string' beginning at 'start' for 'length'. This functions the same as virtual Substrings within eScript such as String[4,6]
Return values
A String
SubStrReplace(str, replace_with, start, length:=0 )#
Parameters
| str | The string to modify |
| replace_with | The string to replace |
| start | Integer start index |
| length | Integer length |
Explanation
Replace portion of string using replace_with, beginning at start for length.
Return values
A String
Errors
- "Index must not be negative"
- "Index out of range"
- "Length out of range"
- "Length must not be negative"
Trim(str, type:=TRIM_BOTH, to_trim:=" " )#
Parameters
| str | The string to trim |
| type | The trim type to use |
| to_trim | The string containing the character, or set of characters, to trim as whitespace |
Explanation
Trims whitespaces from strings.
basic.em constants for type value:
const TRIM_LEFT := 0x1; // Trim whitespace from Left of string. const TRIM_RIGHT := 0x2; // Trim whitespace from Right of string. const TRIM_BOTH := 0x3; // Trim whitespace from Left and Right of string.
Return values
A String
TypeOf( expr )#
Parameters
| expr | a script var |
Explanation
Returns a string, depending on the variable type of the parameter. Is one of: "Dictionary",
"AccountRef", "ConfigFileRef", "ConfigElemRef", "DataFileRef", "DataElemRef", "ScriptExRef", "GuildRef",
"BoundingBox", "DebugContext", "Package", "MenuRef", "MobileRef", "OfflineMobileRef",
"ItemRef", "BoatRef", "MultiRef", "Unknown", "Uninit", "String", "Integer", "Double", "Array", "ApplicPtr",
"ApplicObj", "Error", "Struct", "Packet".
Return values
A string
TypeOfInt( expr )#
Parameters
| expr | The string to parse |
Explanation
returns Integer representation of TypeOf string.
Return values
An Integer
Unpack( str )#
Parameters
| str | A string to unpack |
Explanation
Unpacks a "packed data string" into the variable it represents. See Pack().
Return values
A variable
UnpackJSON( str )#
Parameters
| str | A JSON serialized string |
Explanation
Returns an eScript object representing the serialized JSON string.
The following conversions are done:
JSON -> eScript
number -> double
string -> string
array -> array
object-> struct
bool -> bool
null -> uninitialized object
Return values
Any one of: double, string, array, struct, boolean, or uninit.
Upper( str )#
Parameters
| str | A string to convert |
Explanation
Converts 'string' to uppercase (doesn't work with high-ascii characters or unicode)
Return values
A string