I was working on a cupboard that opens and closes automatically, with two tables: One that tells if the cupboard door is open (and what it contains) , and the other checking the probability of the door opening. However, it tells me (in Windows Frotz) that the “store is out of dynamic memory”, and in Gargoyle it states that I am attempting to “read to write-only address”.
How do I fix these? And what do the different tables (TABLE, PTABLE, LTABLE, PLTABLE, & ITABLE), when should I use them (ting a value, etc.) and what are their limitations?
I don’t know ZIL, but I know a thing or two about the Z-machine.
Tables can be placed anywhere in the first 64 KB of the story file. However, only the first x bytes of this is dynamic memory, i.e. memory that the program is allowed to change during execution (the value x is held in bytes 14 and 15 of the story file).
If your program tries to store a value in a table outside dynamic memory, you can expect to get an error message from the interpreter like “Store outside dynamic memory.”
I would think there is either a keyword you can use to say a table should be stored in dynamic memory and you need to use it here, or there’s a keyword to say a table should be stored in static memory and you’re currently using it but need to omit it.
TABLE is an array in dynamic (writeable) memory without the length in the first slot.
LTABLE is an array in dynamic (writeable) memory with the length of the array in the first slot.
PTABLE is like TABLE but stored in static (readonly) memory.
PLTABLE is like LTABLE but stored in static (readonly) memory.
ITABLE is to init a table of specified length with default values.
All tables defined with P and/or L are word-arrays (each slot is two bytes). If you want a byte-array you define them with TABLE and specify flags for BYTE, LENGTH or PURE.
When you need a table of a predefined size that you fill with data later. It’s shorter to type (example from Zork 1 and its definition of the input buffer):
<ITABLE 120 (BYTE LENGTH) 0>
Instead of table followed by 120 0:
<TABLE (BYTE LENGTH) 0 0 0 0 0 0 0 0 ...>
(I had the ITABLE syntax slightly wrong above, I’ve now changed it.)
A bit more on ITABLE. There’s some alternate syntaxes and also an additional flag, LEXV with special meaning (used when storing the result of parsing the user input). You usually also assign the TABLE to a GLOBAL so it can be referenced inside the routines. Hopefully the following table illustrates the possibilities.