0 votes
by (200 points)
I used to know how to do this but have since forgotten and can't seem to find it.

I want to add a sort of 'fresh start' button to my game, that erases ALL variables. I have several saved across playthroughs (Character Bios) and I want to erase everything including those, but I can't seem to get it to work right. Any suggestions?

1 Answer

0 votes
by (68.6k points)

What kind of variables?  What's wrong with the player using the Restart menu item in the UI bar?

 

If you're simply referring to story variables and you've removed the UI bar somehow, you can show the player the standard restart dialog via the UI.restart() method.  For example:

<<link "Restart">><<run UI.restart()>><</link>>

 

Alternatively.  If you'd rather not use the standard restart dialog, then you may use the Engine.restart() method.  For example:

Restart now? Unsaved progress will be lost.
<<link "Restart">><<run Engine.restart()>><</link>>

Though, as shown, I'd be explicit with the player about what's about to happen because there will be no prompt.

by (200 points)

That's just it...it doesn't forget remembered variables. I wanted things like Character Bios (as you unlock them) to remain unlocked forever. Which works great as I use the following for that:

<<if ndef $variable>
    <<set $variable to "xxxx">>
<</if>>

And then I use <<remember>> instead of <<set>>

I just wanted to give the player an option to reset everything for whatever reason they may want to. Restarting the traditional way, and using the Engine.restart won't accomplish this. That only removes the temporary variables.

I know it's possible...I just forgot how to do it :P

by (68.6k points)

And this is why you give details in your question.  Use of <<remember>> is information we needed to know.

Restarting the traditional way removes all state, which does normally include story variables.  The problem is using <<remember>>, whose sole purpose is to make story variables persist through restarts.

Regardless.  You want the <<forget>> macro to, well, forget things you pinned via <<remember>>.  For example:

→ Forget one $variable
<<forget $variable>>

→ Forget several $variables
<<forget $a, $b, $c>>

 

by (200 points)

Sorry, I assumed when I said I had variables that remained through playthroughs, which is not what happens when <<set>> is used it would be clear what I was attempting.

And I have to forget them one by one? I could have sworn there was a bulk command/script that would clear out everything.

Still, thanks for the reply!

by (68.6k points)

Sadly, developers do bizarre things all the time and you should not expect others to be able to decipher your meaning.  Anyone asking a question should be as explicit and detailed as possible in the question.

In this case, there are other methods one could use to make data persist across playthroughs, so unless we're told which one is being used, we can't know.

Yes.  The <<forget>> macro currently does make you specify them all.  I suppose that I could extend it so that you have the option to more easily purge all story variables persisted via <<remember>>.  That said, if you've persisted so many story variables that using <<forget>> is a chore, then you may be doing something bizarre.

by (44.7k points)

If you only need to do it once just to clean up some "remembered" variables, you could do it manually by starting the game, opening a console window and doing this:

SugarCube.storage.set('remember', null)

Then when you stop the game and restart it, everything should be forgotten.  Unfortunately, that won't work from inside the game.

...