TEXT property 'string' length

I am wondering if there is a way to get the number of characters in a text property? For example, each object may or may not have a (TEXT) property within its declaration (I know this is generally used for ‘Reading’) - I would like to display that text centred on the screen but, as it could vary from item to item, I would need to know the length of the ‘string’.

My Item would look something like this :-

	(DESC "box")
	(LDESC "A wooden box, perfectly square.")
	(TEXT "JAPAN: 1954")

I wish the “JAPAN: 1954” to be printed centred on the screen - currently I am also creating another property called TEXTLEN to pass the length of the text to a CENTRE routine but was wondering if there was anyway in ZIL to get the length of this without the need to explicitly pass the info?

Any help would be appreciated, even if it only expanded my knowledge of the ZIL language :slight_smile:

Regards - Andy G

The only way I know of is redirecting output to a buffer - one that’s big enough - and get the length from that. Something along the lines of:


    <DIROUT -1>                ; "Turn off screen output"
    <DIROUT 3 ,STRBUF>	       ; "Output to buffer"
    <TELL .STR>
    <DIROUT -3>		           ; "Turn off output to buffer"
    <DIROUT 1>		           ; "Output to screen"

I think. But I’m a bit fuzzy on both DIROUT and the syntax for tables.


Doh… Never thought of piping the output to a table and reading that :slight_smile: - Thanks @eriktorbjorn

I tried your routine in my game and it works perfectly - Much appreciated.

1 Like

It’s true that the Z-machine has no way of checking the length of a string without printing it to memory, and what makes it worse is that it’s up to the programmer to make sure the buffer you print to is big enough for the string, or it will write past the end of the buffer and probably destroy some other important data.

Yes, the ‘buffer’ size in @eriktorbjorn example of 80 char should suffice for me (as I only need about 40 for the largest of my strings) but I take your point that we don’t want to end up overflowing across important data! - thanks AG

1 Like

Another way to do this would be to write a PROPDEF/PROPSPEC that computes the length of the string at compile time, then stores it next to the string pointer in the property.

1 Like