Reading and writing indexed text via external files

I’m trying to read some external files into tables (and vice versa). I’m having two main problems:

  1. Released glulx files seem unable to find or recognize files no matter where they’re stored. No matter where I put an appropriately named .txt file, it will not read from it nor write to it. Nor will it create a new file to write to. I’ve tried pretty much every folder structure I could think of, with no luck.

  2. Games run from inform will recognize the file in some locations (Release folder, mostly). But my simplified code neither writes nor reads from the file, although it doesn’t throw run-time errors on my machine. My more complicated code has an additional problem where it tries to write to files instead of reading from them, at least according to the run-time error, but I can’t diagnose whether that’s my problem or not without knowing what’s going wrong with the simple stuff.

This is making it very hard to troubleshoot, since I don’t know where it’s going wrong or what I’m missing.

Can anyone help, or at least confirm these issues on their machine?

(You’ll need to create a .txt file for the code below named testtext. I’m assuming you’ll need something in there, but maybe not?)

[code]“Forum” by Gravel

Test is a room.

The File of Testing is called “testtext”.

When play begins:
say “Looking for file.”;
if File of Testing exists:
say “File found.”;
read File of Testing into the Table of Suspicion;
write the File of Testing from Table of Suspicion.

Every turn:
repeat through the Table of Suspicion:
say example entry.

Table of Suspicion
example (indexed text)
“Blah”[/code]

I believe you’re supposed to create the file using one of the commands for doing so. I don’t think it can just grab a random file off your hard drive.

If so, that’s unfortunate, but might still be of use.

But I can’t get it to create a file from scratch, either. Does it work for you?

Try this:

[code]Test is a room.

The File of Testing is called “testtext”.

When play begins:
write the File of Testing from Table of Suspicion;
say “Looking for file.”;
if File of Testing exists:
say “File found.”;
read File of Testing into the Table of Suspicion.

Every turn:
repeat through the Table of Suspicion:
say example entry.

Table of Suspicion
example (indexed text)
“Blah”[/code]

As NYKevin said, you will want to create your file using Inform, because indexed text in a table is not stored in the file in human-readable form. Open the file produced by the code above and you’ll see that indexed text is encoded like this: S66,108,97,104,0. If you want your external file to be human-readable, you’d do better to avoid the table mechanism and instead parse flat text from the file into variables/tables/lists/whatever.

File extensions are a bit of a mess right now, though a fix is in the offing.

Thanks! That does work, although I think I will experiment some with human readable forms.