How to Save Variable Values to a Text File on Server?

How to save variable values to a text file on the server?

<<set $name to "Mario">>
<<set $age to 20>>

For example, at the end of the game, I want to save “Mario is 20 years old” to mario.txt on the server.
I am using Github repository as the server.


Twine Version: 2.4.1
Story Format: SugarCube

What’s your actual goal? Are you trying to learn about which choices your players make? Are you trying to let people returning to the game resume from where they left off, instead of having to start from scratch? Are you trying to conduct a survey?

The short answer is you can’t do that; if a Twine game could save a file to your server, then anyone on the Internet could save a file to your server, and they probably would. GitHub in particular doesn’t allow that kind of behaviour for fear of exploitation. Even if a Twine game could save a file to your server, what should happen when two people play the game at the same time? Should one person’s results replace the others? Should they be merged somehow, or kept separate? If they’re separate, how would you track which file belonged to which player? If you ask them for a player name when the game begins, how do you ensure that two people don’t sign up as John Doe or whatever?

All these questions can be answered, and you can build or hire services that meet whatever particular set of requirements you want, but there’s no built-in “save variables to the server” function in Twine.

1 Like

Thanks so much for your great info.
Yes, it’s for a survey.
I will explore other options.
Thanks again.

This has come up in some earlier threads—it sends data to Google Drive rather than GitHub. I’m not sure if it still works.