0 votes
by (430 points)
closed by

Well, I tried a code that supposedly allowed me to return from a menu to the latest passage that the player visited while reading the story of the game itself (javascript):

predisplay["Volver al juego"] = function (taskName) {
	if (! tags().contains("menu")) {
		State.variables.return = passage();
	}
};

Then, what I did was this:

 

<<click "Volver al juego" $return>><</click>>

 

And it created a new passage called "$return", so I deleted it but it still was not working. I'm sure that I probably committed some stupid error while trying to implement this code, so I would really appreciate your help :D

closed with the note: Question answered

1 Answer

0 votes
by (68.6k points)
selected by
 
Best answer

There are three parts you need to make this work.

 

1.  Your JavaScript, which goes in the Story JavaScript, should look something like:

predisplay['set-return'] = function (taskName) {
	if (!tags().includes('menu')) {
		State.variables.return = State.passage;
	}
};

What you had should have still worked, but it was long out of date.

 

2.  Your link should look like:

<<link "Volver al juego" $return>><</link>>

While <<click>> would have worked, it's been deprecated for a while now.  That should not have created a new passage, however, as that form of the macro is not recognized by Twine 2's automatic link parser—which is the reason it's suggested, so Twine 2 doesn't keep creating passages named $return.

 

3.  You must tag each of your menu passages with menu, since that's what the predisplay task triggers on.  You didn't mention this step, so I'm guessing you skipped it.

 

by (430 points)
Thank you, I'm stupid, I left a single line of code that was preventing me from making it work. I'm really stupid...
...