Statusbar location garbled in z3 file

The status bar is garbled when I test my .z3 game (it just shows some text from elsewhere in the game, and doesn’t change as player moves).

My game is large for a .z3:
In: 13 source code files 13496 syntactic lines
21101 textual lines 636112 characters (ISO 8859-1 Latin1)
Allocated:
2380 symbols 1014256 bytes of memory
Out: Version 3 “Standard” story file 1.260228 (124.5K long):
22 classes 250 objects
126 global vars (maximum 233) 1577 variable/array space
105 verbs 667 dictionary entries
228 grammar lines (version 3) 400 grammar tokens (unlimited)
114 actions 32 attributes (maximum 32)
29 common props (maximum 29) 49 individual props (unlimited)
89834 bytes of Z-code 1012 unused bytes stripped out (1.1%)
121596 characters used in text 67998 bytes compressed (rate 0.559)
96 abbreviations (maximum 96) 732 routines (unlimited)
11050 instructions of Z-code 7149 sequence points
21510 bytes readable memory used (maximum 65536)
127330 bytes used in Z-machine 3742 bytes free in Z-machine

If it helps, here’s the data map from infodump:

Base End Size
0 3f 40 Story file header
40 41 2
42 1ff 1be Abbreviation data
200 2bf c0 Abbreviation pointer table
2c0 2c7 8 Header extension table
2c8 bcf 908 Object table
bd0 2991 1dc2 Property data
2992 29bf 2e Class Prototype Object Numbers
29c0 2a91 d2 Property Names Table
2a92 2af1 60 Attribute Names Table
2af2 36e0 bef
36e1 38c0 1e0 Global variables
38c1 3c33 373
3c34 3d05 d2 Grammar pointer table
3d06 4270 56b Grammar data
4271 4352 e2 Action routine table
4353 4392 40 Parsing routine table
4393 1387a f4e8 Preposition table
43a9 5351 fa9 Dictionary
5352 5405 b4
5406 1f161 19d5c Paged memory

I’m not doing anything fancy or custom with the status bar (or doing any other drawing-commands under z3)

Constant STATUSLINE_SCORE; Statusline score;

I’m not sure where to begin debugging this.

Possibly related or possibly a hint: I have a bunch of quote arrays at the end of my source code, for use with PunyInform’s QuoteBox. I used to mark those as static arrays (since they never change). However, that would randomly cause programming-errors of out-of-bounds-for-array. I wasn’t able to figure that out, but marked the arrays as no-longer-static, and they started behaving fine. I didn’t care that much about the slightly wasted dynamic memory, so didn’t bother digging into this.

Forgot to mention: status bar works fine in .z5 (the possibly-related-buglet about the static array quotes did happen with z5, but went away when they’re no longer static)

For Z3, the first few globals must be for the status bar. It sounds like you’ve added some new global variables before including PunyInform.

Also note that you haven’t wasted any memory, the combination of static and dynamic memory is limited to 64k.

3 Likes

@andrewj : I did have the statusbar definition after a bunch of other constants. I just moved it to the top, and the garbling still happens.

The reason I tried to save some dynamic memory for the quote arrays is just that some .z5 files won’t play on my retro CPM computer because, while they’re otherwise not too large, they use too much dynamic memory for my system. I was just hoping to avoid that fate :slight_smile: But my game is well below the threshhold for that for most systems, I’d image.

Oh yeah, it can help for retro systems.

1 Like

Definitely no Global definitions before including any part of PunyInform?

@andrewj is right. This is always because the author has defined one or more global variables before including “globals.h”.

If you look at minimal.inf, it says where global variables should preferrrably be defined.

2 Likes

Ah, that was it, @andrewj !

At first, I thought you meant just “declare the Statusbar style” about other things. But now I’ve moved my game-specific globals to after including “globals.h” and It works!

Thanks so much, @andrewj ! You’ve been so helpful in these past few weeks, and I really appreciate that.

2 Likes

Thanks, @fredrik . I hadn’t looked at minimal.inf in a long while. You’re quite right; it’s very specific and helpful for the ordering of things.

2 Likes

In Z-machine v3, the interpreter is responsible for drawing the statusline. But the interpreter can’t guess which room name should be printed, or the score or the number of moves. So, part of the contract for version 3 is that the very first global holds the location, the second global holds the score, and the third global holds the number of turns. If you define a global before including globals.h, you throw this off - the interpreter will look at your global, and interpret its value as an object number, printing the name of that object on the statusline. If the value is 0, or higher than the highest object number in your game, you’ll see garbage,

6 Likes