Inform 7: Reading files while running the game in Parchment

Hello all,

I have tried several times to read and write files, and never successfully.

[code]When play begins:
if File of Endings exists:
read File of Endings into the Table of Endings;

Check quitting the game:
write File of Endings from the Table of Endings.

Table of Endings
Ending Occur
“Win” False
“Lose” False
“Draw” False[/code]

This always generates *** Run-time problem P34: Attempt to save a table to a file whose data is unstable: table 'Table of Endings'.

However, I want to go a step further than just reading the file locally. I am hosting my game online, and I want it to be able to read a file on my computer (the server). Is this possible? Unfortunately, searching “File” doesn’t come up with much.
*I am OK with not being able to write to the file, I just want to be able to read it.

In Parchment(*) the file-storage calls access cookies(**) in the user’s browser, not files on the web server. So no, you can’t do that that way.

The calls should work, though. I’m not sure what the “data is unstable” error is coming from. I haven’t tested I7’s API for this feature, only the underlying functionality.

(* This is actually Quixe embedded in Parchment, not that it matters, except to clarify the question for onlookers.)
(** Browser-local storage.)

If you want to read a lot of data at run-time, by far the easiest plan is to compile it into the game file. (That is, put it in the table to begin with.) If that doesn’t fit what you’re trying to do, tell us more. :slight_smile:

I am, perhaps foolishly, attempting to monetize my game. To that end, I will have free users and premium users. My strategy to segregate the groups is to have a login system, in-game. I give the premium users a code, they log in with it, and can access premium content. Mechanically, when the players log in, what I want to do is check the code they enter against a file on the server, that has a list of codes for every premium user.

I could do this in the game code, but then I would have to publish a game update every time someone buys in, and that would get really annoying if I am halfway through the next update. Also, I am guessing it is possible to decompile code, so that would defeat the purpose.

This is regarding the “unstable” error message. The first column of your “table of endings” is filled with texts. Unfortunately, as annoying as it is, that is one of several things Inform won’t write to a file.

If you absolutely need that column to be text, you could try indexed text instead. The viability of this probably depends on what exactly you plan to do with the table. For now, I suggest you read the bottom of chapter 22.12 in the inform manual. It discusses the situation on why a non-indexed text can’t be written out.

As to your quest to separate the free users from the premium, I’m not really sure of how to go about that effectively, myself. I would be interested to learn about it if you do find a way, as the concept could be used for some other interesting features as well.

You might have more luck authenticating by Javascript. With a custom build of parchment you can run javascript code from Inform:

Look up Vorple for some Inform 7 phrases to access the Inform 6 code.

There are a couple of things that make pure JavaScript (which Parchment is) a less than optimal approach to providing paid content, not the least that if Parchment can access the passcode file so can anyone else. You would have to encrypt the file somehow and implement the decrypting algorithm in the story file.

I suggest you implement the login system in the server using a server-side language or the web server’s authenticating system, then compile and serve two versions of the game: one to free users and another to premium users.

I don’t really have a good solution, but I just wanted to say, thank you Dannii and Juhana. Both of your works made it possible for me to get my game out there in the first place.

1 Like