Array functions
Functions
- array_key
- arrayexpr
- create_array
- fix_array
- free_array
- get_array
- len_array
- load_array
- resize_array
- save_array
- scan_array
- set_array
- temp_array
array_key
mixed array_key(int arrayID, int index)
-Don’t use it directly; it is generated by the compiler in foreach loops.
arrayexpr
int arrayexpr(mixed key, mixed value)
-Don’t use it directly; it is used by compiler to create array expressions.
create_array
int create_array(int size, int nothing)
-Creates permanent array (but not “saved”).
fix_array
void fix_array(int arrayID)
+Don’t use it directly; it is generated by the compiler in foreach loops.
- for lists, returns index back (no change).
- for maps, returns a key at the specified numeric index (don’t rely on the order in which keys are stored though).
- can be checked if given array is associative or not, by using index (-1): 0 - array is list, 1 - array is map.
arrayexpr
int arrayexpr(mixed key, mixed value)
+Don’t use it directly; it is used by compiler to create array expressions.
- assigns value to a given key in an array, created by last
create_arrayortemp_arraycall. - always returns 0.
create_array
int create_array(int size, int nothing)
+Creates permanent array (but not “saved”).
- if
size >= 0, creates list with given size. - if
size == -1, creates map (associative array). - if
size == -1andflags == 2, creates a “lookup” map (associative array) in which the values of existing keys are read-only and can’t be updated. This type of array allows you to store a zero (0) key value. - returns array ID (valid until array is deleted).
fix_array
void fix_array(int arrayID)
Changes “temporary” array into “permanent” (“permanent” arrays are not automatically saved into savegames).
free_array
void free_array(int arrayID)
-Deletes any array.
get_array
mixed get_array(int arrayID, mixed key)
-Returns array value by key or index (shorthand: arrayID[key]).
- If array with given arrayID doesn’t exist, returns 0.
len_array
int len_array(int arrayID)
-Returns number of elements or key=>value pairs in a given array.
load_array
int load_array(mixed key)
-Load array from savegame data by the same key provided in “save_array”.
resize_array
void resize_array(int arrayID, int size)
-Changes array size.
save_array
void save_array(mixed key, int arrayID)
-Array is saved (arrayID is associated with given “key”).
scan_array
mixed scan_array(int arrayID, mixed value)
-Searches for a first occurence of given value inside given array.
set_array
void set_array(int arrayID, mixed key, mixed value)
-Sets array value (shorthand: arrayID[key] := value).
temp_array
int temp_array(int size, int nothing)
-Works exactly like “create_array”, only created array becomes “temporary.”