Text Capture conflict with file writing

This is a phenomenon I had difficulty reproducing. There may be a simpler way to do it, but this works:

[code]Include Text Capture by Eric Eve

Test is a room.

Carry out jumping: start capturing text.

Table of Interruptions
incidents (number)
0

The file of interruptions is called “interrupt”.

Every turn:
Choose row 1 in Table of Interruptions;
increment incidents entry;
write file of interruptions from Table of Interruptions.

Last every turn:
say “Don’t interrupt me!”;
showme whether or not text capturing is active;

Before reading a command:
stop capturing text;
say “START CAPTURE:[line break][the captured text][line break]END CAPTURE.”;

test me with “jump”.[/code]

What happens is that the text “Don’t interrupt me!” (and everything after it until “stop capturing text”) doesn’t get captured. I expect this to be a hard problem to fix, and I’m not even sure whose responsibility it is. Eric, if you can fix this, you deserve a promotion. Anyone else, if you can fix this, you deserve Eric’s job! :smiley:

The file operations in the standard library (FileIO_Open) seem to set the current output stream to the file, but never set it back. I’m not sure why this works at all, actually.

EDIT: Whoop, I see where it sets it back. (In FileIO_Close, the call to glk_set_window.)

So the problem is that this FileIO code assumes that output was originally set to the main window. The easiest fix is just to disable text capture before the “write file” statement and reactivate it afterwards.

So you mean replace the I6 code for writing files with something that disables and then re-enables text capture? Is that the two functions you just mentioned or something else?

I meant put more code before and after the “write file of interruptions…” line.

I remember running into this problem with Flexible Windows. For your purposes capmikee I think it will be better to fix the stream in the file IO functions. I think this would count as a bug too.

It shouldn’t be hard to store the current stream in FileIO_Open() using glk_stream_get_current() and then set that in FileIO_Close() using glk_stream_set_current() after the glk_set_window() call. Or could glk_set_window() be removed, if all it was being used for was the stream?

You have to set the output stream to something after you close the file, or the next thing you print is lost. (With a Glk error.)

Saving it with glk_stream_get_current() and then restoring it is correct. I’m not sure you want to do it in FileIO_Open/FileIO_Close. If those functions rely on a global, you’ve just moved the nestability problem elsewhere.

The functions FileIO_PutTable, FileIO_PrintContents, etc have the open and close in the same function. This means you can save and restore the current stream without relying on a global.

If needed we could store the old stream id in the file struct, but it doesn’t look like FileIO_Open is called outside the PutTable, PrintContents functions etc. I don’t know which is more aesthetically ideal, but modifying FileIO_PutTable is probably easier.

capmikee, I’ll see if I can work on an extension for this later today.

The patch was pretty easy to take care of.

Bug: inform7.com/mantis/view.php?id=1429
Patch: github.com/i7/extensions/blob/m … atches.i7x

Great! Thanks, guys.