Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sfall-team/sfall into bet…
Browse files Browse the repository at this point in the history
…ter-docs
  • Loading branch information
burner1024 committed Oct 18, 2023
2 parents 55eb1ec + 143ec75 commit a26ec06
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 70 deletions.
26 changes: 13 additions & 13 deletions artifacts/scripting/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ _*mixed means any type_
#### `void resize_array(int arrayID, int size)`
- changes array size
- applicable to maps too, but only to reduce elements
- there are number of special negative values of "size" which perform various operations on the array, use macros `sort_array`, `sort_array_reverse`, `reverse_array`, `shuffle_array` from **sfall.h** header
- there are number of special negative values of "size" which perform various operations on the array, see macros `sort_array`, `sort_array_reverse`, `reverse_array`, `shuffle_array`, `sort_map_value`, and `sort_map_reverse` from **sfall.h** header

#### `void free_array(int arrayID)`
- deletes any array
Expand All @@ -206,18 +206,7 @@ _*mixed means any type_

#### `int len_array(int arrayID)`
- returns number of elements or key=>value pairs in a given array
- if array is not found, returns -1 (can be used to check if given array exist)

#### `mixed array_key(int arrayID, int index)`
- 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

#### `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_array` or `temp_array` call
- always returns 0
- if array is not found, returns -1 (can be used to check if given array exist)

#### `void save_array(mixed key, int arrayID)`
- makes the array saveable; it will be saved in **sfallgv.sav** file when saving the game
Expand All @@ -230,6 +219,17 @@ _*mixed means any type_
- loads array from savegame data by the same key provided in `save_array`
- returns array ID or zero (0) if none found

#### `mixed array_key(int arrayID, int index)`
- 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

#### `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_array` or `temp_array` call
- always returns 0


___
### BACKWARD COMPATIBILITY NOTES
Expand Down
Loading

0 comments on commit a26ec06

Please sign in to comment.