Is there any way to save a password in Twine?

0 votes
asked Feb 9 by SmuJamesB (2,650 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
answered Feb 9 by idling (10,670 points)
selected Feb 13 by SmuJamesB
 
Best answer

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

commented Feb 14 by SmuJamesB (2,650 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
answered Feb 9 by greyelf (97,410 points)
How are you planing on using the saved password? What is the purpose of saving it?
commented Feb 9 by SmuJamesB (2,650 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.
commented Feb 9 by greyelf (97,410 points)
edited Feb 9 by greyelf

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.

commented Feb 14 by SmuJamesB (2,650 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
answered Feb 9 by mazhem (1,150 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
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...