clearing the contents of an external file

My work in progress tracks achievements across multiple playthroughs. In fact, it tracks a lot of things. Storing tables in external files seems like the right way to do this.

If I understand the machinery correctly, the phrase write [external file] from [table] appends rather than replaces. Is that right? In other words, in a case where I might track a counter across playthroughs, every time my program updated the external file, there would be a new record with the updated counter. This makes sense logically, I can see why this would be so.

Question one: do I have this right?

If the answer to question one is “yes,” what would be the best way to get a new table every time? The docs don’t mention a means of clearing the file, unless I’ve missed it. I am aware of an i6 method for deleting an external file (I found it here on this forum).

Question two: barring other methods, what approach is best? Delete? Something else?

No it replaces the file with the new table. The only phrase that will append to a file is “append (text) to (external file)”.

1 Like

Ah, you’re right! There was a flaw in my testing.

For any people finding this in a search, here’s a short demo of how it works:

bare-bones example
Lab is a room.

file tabletest is called "tabletest".

table of writetesting
text (a text)
--


table of readtesting
text (a text)
--

filetesting is an action applying to nothing.
understand "filetest" as filetesting.
understand "ft" as filetesting.

carry out filetesting:
	choose row one in the table of writetesting;
	now text entry is "Yes!";
	write file tabletest from table of writetesting;
	read file tabletest into table of readtesting;
	showme the contents of table of readtesting;
	say paragraph break;
	choose row one in the table of writetesting;
	now text entry is "No!";
	write file tabletest from table of writetesting;
	read file tabletest into the table of readtesting;
	showme the contents of the table of readtesting;

test me with "ft".
1 Like