I was trying to set up a table arary that would vary in size based on the number of objects. In Glulx, there is a “system constant” (name given in Inform 6.34 release notes) called #highest_object_number that is defined during compilation, which would hold the value that I want, but the declaration:
is being rejected ("Error: Expected constant but found "). Based on the error, I’m assuming that the compiler is deciding that the value of #highest_object_number is being treated like a variable, not a constant. A declaration using a “hard-coded” constant:
The values of the system constants are not known until all of the source code has been compiled. Your example uses #highest_object_number; obviously it doesn’t make sense for this to have a value until all the objects have been created. All arrays, objects, strings, and functions must also be created and laid out in memory.
There is a following step where values (in function code) can be filled in with system constants. For example, you could have a function
[ func x;
x = #highest_object_number;
];
Filling in that value does not change the layout of memory. But it doesn’t make sense to fill in an array length that way.
@zarf, I did understand that it was a number that had to be discovered during compilation, but it seems like the compiler is able to decide what that number is by that point in the code generation – after all, the constant ObjectCount is set correctly.
That’s why I had thought that by putting that value into a constant, the compiler would have determined it prior to creating the code for the array declaration. But it just doesn’t work that way, it seems? (I’m afraid that I don’t know much about how compilers work on the inside.)
I had also hoped that those values being called system constants meant that they should be treatable as such. Oh, well – now I know that they’re not, so thank you.
@Dannii, thank you for the tip. I will look into that approach!
ObjectCount is not in fact set until that last step of filling in constant values. Before that, it’s a placeholder which says “fill in #highest_object_number here.”