0 votes
by (2.7k points)
Is there any way to save a password in Twine? Using the "<<textbox>>" macro, I can create a simple password system, but is there any way of saving the password using the user's browser?

3 Answers

+1 vote
by (23.6k points)
selected by
 
Best answer

You might be looking for the <<remember>> macro.

by (2.7k points)

Works fine. I had a slight problem that the variable kept being reset with every restart of the game; just added the following code to StoryInit:

<<if ndef $LoggedIn>><<set $LoggedIn = false>><</if>>

To stop it resetting the variable every time.

+1 vote
by (159k points)
How are you planing on using the saved password? What is the purpose of saving it?
by (2.7k points)
The saved password will be used to access a cheat system. Only players I give the  code to can use it, but it is annoying to have to re-type the password every time. I have set up a system using a $LoggedIn variable to save your password for that session, but it is not permenant.
by (159k points)
edited by

If I understand correctly you are comparing a password entered by the player (or hopefully loaded from storage) against a known value to determine if a cheat system should be enabled.

The problem with that technique is that the known value is contained within the source code of the story HTML file, and that source code is fairly easier to read for anyone with a little HTML knowledge (or the ability to google it) which means that the known value is is fairly easy to find. So anyone who can find it can by-pass that security system.

You could try changing the above technique to use some formula to determine if the entered (stored) password is correct, but again the source code applying that formula is accessible to the player so they are again able to by-pass it.

Anyway to answer your question about how to persist a value between play-throughs.

You could use the same Javascript localStorage.getItem() and localStorage.setItem() functions used within the Javascript example of this answer to the Global Stats - How do you... question to load & save the password within the player's web-browser's Local Storage.

or as as suggested by @idling, the <<remember>> macro that I forgot SugarCube has.

by (2.7k points)
Works fine. I do not have to worry about people hacking the system, as these tools are for testing purposes. Anybody with that much HTML knowledge would probably make a good tester.
+1 vote
by (1.1k points)
If you want to save the password you could save the state of the game by using the sugarcube save system, or in an advanced way use the API through either custom saving in the save settings when you put in the password or you could try something with this http://www.motoslave.net/sugarcube/2/docs/api-setting.html#setting-api-method-save

I'm new to jQuery so I can only give ideas in this case
...