Storages
Introduction
Storages are arrays of registers that can be accessed when using VariationalAction2. Registers (temporary and persistent alike) always have a size of 4 bytes. If you're writing them using smaller sizes (anything but type 89/8A), the given value will be sign-extended to 4 bytes. Therefore, be careful when you read a register using a bigger size than it was written with. This also applies to registers read by TTDPatch; if not indicated specifically, TTDPatch reads all 4 bytes of the register.
Description
Temporary storage
Size: 100 (before TTDPatch r1301) or 10F (since TTDPatch r1301 and OpenTTD r9707)
Data storage: Operator \2sto (0E) allows to store values inside the registers of this storage.
Data access: The first FF registers can be read using variable 7C. The rest of the values are write only: they are used to pass extra data to some 4x and 6x variables, as well as for returning extra data from callbacks.
Temporary storage contains values local to the current VariationalAction2 chain. When a new chain starts, the values inside the temporary storage are undefined. Therefore, they should not be used unless they have been properly initialized.
Persistent storage
Size: 10
Data storage: Operator \2psto (10) allows to store values inside the registers of this storage.
Data access: The registers can be read using variable 7D. Note that it is possible to access the persistent storage of related objects (see VariationalAction2#Type).
Features that support it: Industries (0A)
Persistent storage is associated to a single item. When the item is created, all of the values of the persistent storage are set to zero. Persistent storage values cannot be accessed or modified by items that are being created.
Persistent storage accessed by GRFID
Size: 10 for each GRFID
Data storage: Operator \2psto (10) allows to store values inside the registers of this storage. The GRFID to access must be stored in temporary register 0x100 before using Operator 10. 0xFFFFFFFF can be used to access the GRFID of the item using the current VariationalAction2 chain.
Data access: The registers can be read using variable 7D. Note that it is possible to access the persistent storage of related objects (see VariationalAction2#Type). The GRFID to access must be stored in temporary register 0x100 before checking variable 7C. 0xFFFFFFFF can be used to access the GRFID of the item using the current VariationalAction2 chain.
Features that support it: Towns
Features supporting persistent storage accessed by GRFID are not restricted to a single persistent storage; there is a persistent storage associated to every GRFID. An item only has write access to the persistent storage associated to its own GRFID, but it can read the registers of any GRFID. Persistent storage values cannot be accessed or modified by items that are being created.