Added markdown version of hookscripts.txt

Some edits to documents.
This commit is contained in:
NovaRain
2021-04-07 21:09:55 +08:00
parent acf859bebf
commit 278bfdc841
3 changed files with 906 additions and 17 deletions
+14 -15
View File
@@ -165,7 +165,7 @@ ___
_*mixed means any type_
**`int create_array(int size, int flags)`**
#### `int create_array(int size, int flags)`
- creates permanent array (but not "saved")
- if `size >= 0`, creates list with given size
- if `size == -1`, creates map (associative array)
@@ -173,13 +173,13 @@ _*mixed means any type_
* NOTE: in earlier versions (up to 4.1.3/3.8.13) the second argument is not used, just use 0
- returns array ID (valid until array is deleted)
**`int temp_array(int size, int flags)`**
#### `int temp_array(int size, int flags)`
- works exactly like `create_array`, only created array becomes "temporary"
**`void fix_array(int arrayID)`**
#### `void fix_array(int arrayID)`
- changes "temporary" array into "permanent" ("permanent" arrays are not automatically saved into savegames)
**`void set_array(int arrayID, mixed key, mixed value)`**
#### `void set_array(int arrayID, mixed key, mixed value)`
- sets array value
- if used on list, "key" must be numeric and within valid index range (0..size-1)
- if used on map, key can be of any type
@@ -187,59 +187,58 @@ _*mixed means any type_
* NOTE: to add a value of 0 for the key, use the float value of 0.0
- this works exactly like statement: `arrayID[key] := value;`
**`mixed get_array(int arrayID, mixed key)`**
#### `mixed get_array(int arrayID, mixed key)`
- returns array value by key or index
- if key doesn't exist or index is not in valid range, returns 0
- works exactly like expression: `(arrayID[key])`
**`void resize_array(int arrayID, int size)`**
#### `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
**`void free_array(int arrayID)`**
#### `void free_array(int arrayID)`
- deletes any array
- if array was "saved", it will be removed from a savegame
**`mixed scan_array(int arrayID, mixed value)`**
#### `mixed scan_array(int arrayID, mixed value)`
- searches for a first occurence of given value inside given array
- if value is found, returns it's index (for lists) or key (for maps)
- if value is not found, returns -1 (be careful, as -1 can be a valid key for a map)
**`int len_array(int arrayID)`**
#### `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)`**
#### `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)`**
#### `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
**`void save_array(mixed key, int arrayID)`**
#### `void save_array(mixed key, int arrayID)`
- makes the array saveable; it will be saved in *sfallgv.sav* file when saving the game
- array ID is associated with given "key"
- array becomes permanent (if it was temporary) and "saved"
- key can be of any type (int, float or string)
- if you specify 0 as the key for the array ID, it will make the array "unsaved"
**`int load_array(mixed key)`**
#### `int load_array(mixed key)`
- loads array from savegame data by the same key provided in `save_array`
- returns array ID or zero (0) if none found
___
### BACKWARD COMPATIBILITY NOTES
For those who used arrays in their mods before sfall 3.4:
* There is an INI parameter **ArraysBehavior** in "Misc" section of *ddraw.ini*. If set to 0, all scripts which used sfall arrays before should work. This basically changes that `create_array` will create permanent arrays which are "saved" by default and their ID is also permanent. It is 1 by default.
* There is an INI parameter **ArraysBehavior** in **Misc** section of ddraw.ini. If set to 0, all scripts which used sfall arrays before should work. This basically changes that `create_array` will create permanent arrays which are "saved" by default and their ID is also permanent. It is 1 by default.
* How savegame compatibility is handled?
Saved arrays are stored in *sfallgv.sav* file (in savegame) in new (more flexible) format, just after the old arrays. So basically, when you load older savegame, sfall will load arrays from old format and save them to new format on next game save. If you load savegame made with sfall 3.4 using sfall 3.3 (for example), game shouldn't crash, but all arrays will be lost.
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -753,8 +753,8 @@ int ret0 - overrides the roll result
HOOK_BESTWEAPON (hs_bestweapon.int)
Runs when the game (AI) decides which weapon is the best while searching the inventory for a weapon to equip in combat.
This is also runs when the player presses the "Use Best Weapon" button on the party member control panel.
Runs when the AI decides which weapon is the best while searching the inventory for a weapon to equip in combat.
This also runs when the player presses the "Use Best Weapon" button on the party member control panel.
Critter arg0 - the critter searching for a weapon
Item arg1 - the best weapon chosen from two items