0 votes
by (410 points)
I'm using the <<run Engine.restart()>> macro at the end of my game, but when the game restarts it takes it to the very first passage instead of the title screen, which is the third passage. How can I get it to restart on the title screen?

1 Answer

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

Create a passage called "StoryInit" (if you haven't already) and put this at the top of it:

<<if def $SkipIntro>>
	<<set Config.passages.start = "TitleScreen">>

So now it will look to see if $SkipIntro is defined when the game starts, and if it is, then it will start at the "TitleScreen" passage.  See Config.passages.start for details.

Then, on the page where you're restarting the game, you would use something like this code:

<<link "Restart">>
	<<remember $SkipIntro = true>>
	<<run Engine.restart()>>

Using the <<remember>> macro causes SugarCube to remember the value, even if you or the user restart the game.

If you want to make it so that if they manually restart the game it shows the normal intro instead of the title screen, then you should add this to your "TitleScreen" passage:

<<forget $SkipIntro>>

The <<forget>> macro will remove the $SkipIntro variable, so it will be undefined again.  Now if the user reloads the game it will start at your default start passage again.

Hope that helps! smiley

by (410 points)
Thanks very much! That helped a lot. One more thing -- I'm not sure if you'll be able to answer this, but is there a way to get to a different title screen based on the ending the player got? (ex. bad ending = gruesome-looking title screen, good ending = normal-looking title screen)
by (410 points)
Wait-- actually, that didn't work. When the game is first loaded it should start at the very first passage but when it is restarted after the ending it should start at the title page. Is there a way to do that?