CaravelGames / drod

The official public repository of Deadly Rooms of Death and DROD RPG
http://caravelgames.com
56 stars 17 forks source link

RPG: Add support for array script variables #618

Closed Hypexion closed 1 month ago

Hypexion commented 2 months ago

Adds new functionality to scripts by allowing arrays. A script variable starting with a # becomes an array. To avoid weird issues with serialization, once a variable is created, it can't be renamed in a way that changes its "arrayness".

Internally, arrays are technically maps, as they can be non-continuous. Negative indexes are also supported, although this is not unheard of in some languages.

Arrays are serialized back to the packed stats object when saving. The number of active items in the array is saved as the first value, followed by a sequence of key/value pairs. The readBpUINT and writeBpUINT functions have been moved to CDbSavedGame to allow them to reused for this. To save space, values of zero are not packed when serializing (as getting an int value from a map will return zero is no value is assigned to that key).

New script commands have been added to write to arrays. Reading from arrays is handled by expression parsing functions.

(This is #587 for DROD RPG. Since RPG does not have local character variables, support for local arrays has not been added.)