Recording a table to a file

Of course, as usual, this is imbecile and I will find what I do wrong as soon as I click on “submit”.
Anyway: I can’t seem to be able to write a table into a file. The file is created but is empty.

Can anyone see where I’m wrong? (Warning, very mild spoiler inside)

[spoiler][code]File of AAFILE is called “AAAc”.

When play begins:
if File of AAFILE exists, read File of AAFILE into the Table of Tasks Achieved.

Table of Tasks Achieved
Points Title (indexed text) Explanation (indexed text) Earned
1 “A Hell of a Storm” “You watched the sky turn dark” a value
1 “A Dark Omen” “You have seen the dark side of the sky”

To record (T - text) as achieved:
choose row with a Title of T in the Table of Tasks Achieved;
if there is no earned entry:
now the earned entry is 1;
increase the score by the points entry;
consider the fix baseline scoring rule;
say “[bracket]You have earned the [bold type][Title entry][roman type] achievement[close bracket][paragraph break]”;
write File of AAFILE from the Table of Tasks Achieved.[/code][/spoiler]

Thank you very much.

Hey Marco. First issue: I don’t think you can store indexed text in a table. But this issue (which I haven’t checked) is not relevant because you have a bigger issue – you cannot write a table to a file if the table contains text.

I began to turn your example into a test project for myself, and eventually hit a run-time error with this explanation.

“The only tables which Inform allows us to save into files are those only containing safe data: numbers, units, times of day and kinds of value with named alternatives. Text, in particular, is not allowed, and nor are scenes, rules or rulebooks.”

  • Wade

Section 22.12 says indexed text can be written out to a file. The problem is probably the Earned column. Can you put in a specific kind?

Btw, you may like to look at how Kerkerkruip does its achievements: github.com/i7/kerkerkruip/blob/ … ta.i7x#L64
In short, we have a new kind of value, meaning we can avoid using indexed text. Their descriptions are hardcoded in a second table: github.com/i7/kerkerkruip/blob/ … h.i7x#L369

But the guide and examples add that (indexed text) tag and they work fine.
All I have to achieve, btw, is storing the last column value so that when it becomes a “1” it is saved.

Try Earned (a number)

For the first time, this gives a runtime error:

“trying to save a table to an unstable file”.
Fun part is this is happens when i restart the game and the table is actually saved FROM the file.

That probably happened because it couldn’t save it properly before. (Inform adds an asterisk to the beginning of the file to show its in use, but if the error happened before it was finished then maybe it didn’t get removed.) Try deleting the file to see if it works.

Nope :frowning:

I think I’m going to copy the complex system from KK. Although I need 20% of all that includes.

(FYI, I tried to convert the value columns into indexed text also, but it just didnt work)


Edit: But I don’t seem to get it going. The thing is too complex and I’m really losing my way home.
I will try more tweaking to my own code. God help me.

There’s the solution.

[spoiler][code]Table of Tasks Achieved
Pos Title (indexed text) Explanation (indexed text) Earned (number)
1 “Hell of a Storm” “You watched the sky turn dark” a value
2 “A Dark Omen” “You have seen the dark side of the sky”
[and MANY other]

Table of Held Achievements
stored (number)
with 23 blank rows

To record (T - text) as achieved:
choose row with a Title of T in the Table of Tasks Achieved;
if there is no earned entry:
now the earned entry is 1;
say “[bracket]You have earned the [bold type][Title entry][roman type] achievement[close bracket][paragraph break]”;
Let L be the Pos entry;
choose row L in the Table of Held Achievements;
now the stored entry is 1;
write File of AAFILE from the Table of Held Achievements.[/code]

With an impressively convoluted excuse for a coding at the very beginning (I sense this can be done better, but can’t tell how):

When play begins: if File of AAFILE exists: read File of AAFILE into the Table of Held Achievements; repeat through the Table of Tasks Achieved: if there is no earned entry: Let C be the Pos entry; choose row C in the Table of Held Achievements; if there is a stored entry: choose row C in the Table of Tasks Achieved; now earned entry is 1;[/spoiler]

God saved me.

Thank you for your help Dannii & Wade!