I’m trying to get something done in Glulx (with the Flexible Windows extension by Jon Ingold), and this is the first time I’m really tangling with things like streams and windows and rocks.
My main goal is to try to figure out where the cursor is on a text grid window after printing something to it. Although it is possible to move the cursor to a set of specified screen coordinates, it does not seem possible to ask for the coordinates where the cursor currently is. Am I missing something in the Glk spec?
If it’s not possible to obtain the position directly, the next option seems to be to try to calculate it. Echo streams to memory can capture the text going to the text grid window, and it’s possible to read the stream position and inspect the characters streamed so far. I have some code that is (more or less) working on the 6M62 IDE interpreter, but it’s not working on Git 1.3.5 (Gargoyle 2019) or Git 1.3.7 (Gargoyle 2023).
The specific issue with Git is that attempting to read the contents of the memory array to which the echo stream is pointed is always returning zero instead of the expected captured character. Manual inspection of the target array after printing shows only zero-value bytes for the first several locations. Before reading, the code does check that the echo stream exists and is set as the echo stream for the window in question. The captured characters are returned correctly by the IDE interpreter, so I’m not sure what the cause is.
Does Git support echo streams for text grid windows?
Here’s some test code illustrating the difference:
test code
"Echo?"
Include Flexible Windows by Jon Ingold.
Include (-
Constant gg_TMP_ARRAY_LEN = 200;
Array gg_strtmparray -> gg_TMP_ARRAY_LEN;
Global gg_countingechostream;
Constant gg_COUNTING_ECHO_ROCK = 999;
Array gg_streamcharcount --> 2; ! -->0 = readcount, -->1 = writecount
Global gg_echostreammark;
[ RetrieveEchoRock chk_strm rockval;
chk_strm = glk_stream_iterate(0, 0);
while (chk_strm) {
rockval = glk_stream_get_rock(chk_strm);
if (rockval == gg_COUNTING_ECHO_ROCK)
return chk_strm;
chk_strm = glk_stream_iterate(chk_strm, 0);
}
rfalse;
];
[ EstablishEchoStream win ;
gg_countingechostream = RetrieveEchoRock();
if (gg_countingechostream) {
glk_stream_close(gg_countingechostream, gg_streamcharcount);
}
gg_countingechostream = glk_stream_open_memory(gg_strtmparray, gg_TMP_ARRAY_LEN, filemode_Write, gg_COUNTING_ECHO_ROCK);
glk_window_set_echo_stream(win, gg_countingechostream);
gg_echostreammark = 0;
];
[ CheckEchoStream strm_pos;
strm_pos = glk_stream_get_position(gg_countingechostream);
print "^<", strm_pos, " chars streamed, first 4 array values are: ", gg_strtmparray->0, " ", gg_strtmparray->1, " ", gg_strtmparray->2, " ", gg_strtmparray->3, ">^"; ! should reflect "TEST"
];
-)
To establish echo stream for (win - g-window):
(- EstablishEchoStream( {win}.(+ ref number +) ); -).
To check echo stream:
(- CheckEchoStream(); -).
When play begins:
establish echo stream for main window;
say "TEST";
check echo stream.
Place is a room.