Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to restart a story properly?

Hi All,
Previously I restarted a story in game by just linking to the start passage and in my start passage I had all my variables which then reset.
I was advised this was poor form and that variables should go in a special passage StoryInit, I've done that but now when I link to start to restart the story none of the variables reset so how am I supposed to do it?
Thanks
nowherecity24

Comments

  • Using SugarCube, which I assume you are based on mention of the StoryInit passage, use:

    <<script>>
    state.restart();
    <<endscript>>

    I'm not sure how you'd do it in any of the other story formats but this might help.
  • MoLoLu wrote:
    Using SugarCube, which I assume you are based on mention of the StoryInit passage.

    The StoryInit special passage also exists in the non-SugarCube headers in later versions of Twine.
  • (Seriously, let us know which story format you're using.  Even amongst the vanilla headers, there are differences.  Knowing the story format is important.)

    SugarCube:

    Simply do the following wherever you want a Restart link:
    <<click "Restart">><<script>>UISystem.restart()<</script>><</click>>
    That will open the standard restart confirmation dialog.


    Vanilla story formats:

    I don't know of a simple way that doesn't involve some complications, so something a little more involved is in order.  Where will you be putting this restart link (or links)?
  • greyelf wrote:
    The StoryInit special passage also exists in the non-SugarCube headers in later versions of Twine.


    Good to know. Haven't looked at the Vanilla headers in forever.

    Speaking of the vanilla headers, couldn't you write a script passage set to prerender that calls the restart function the game's UI calls if a certain variable is set? I'm not sure that would actually work as I've only ever scripted for SugarCube but it's the only thing I can think of that would be relatively simple to implement.
  • MoLoLu wrote:

    Speaking of the vanilla headers, couldn't you write a script passage set to prerender that calls the restart function the game's UI calls if a certain variable is set? I'm not sure that would actually work as I've only ever scripted for SugarCube but it's the only thing I can think of that would be relatively simple to implement.


    It's important to know where the link(s) need to be first.  Otherwise, a naive solution could end up doing something terrible like attaching multiple event handlers to the same element.  However, yes, if the links are inside the passage display area, then you could use a postrender task to attach an event handler which would call Interface.restart().

    Anyway, that's why I asked above where nowherecity24 is putting these link(s).
  • Hi All,
    Thanks for your replies
    I'm using sugarcane format with a stylesheet that gives me a central story page and then a stats box to the left.
    I find it easy to read and it copes well with how I set up my games (apart from one thing which I just discovered that I will ask for help in yet another post!)

    I know lots of you use sugarcube but as it puts a menu to the left I don't have the ability to play with that.

    In my game I link to restart from an endgame passage  example You have reached an end game [[restart|start]]

    From your posts is appears I may as well just put all the variable inits back in the start passage as that works.
    Is there any benefit to using StoryInit in my case?
    Thanks
    nowherecity24
  • nowherecity24 wrote:

    In my game I link to restart from an endgame passage  example You have reached an end game [[restart|start]]


    Okay.  Format is Sugarcane and you're going to use this inside normal passages.

    Try this: (goes in a script tagged passage)

    postrender["activateRestartLinks"] = function (context) {
    var links = context.querySelectorAll("a.restartLink");
    if (links.length !== 0) {
    for (var i = 0, iend = links.length; i < iend; i++) {
    addClickHandler(links<i>, function () {
    Interface.restart();
    });
    }
    }
    };
    And then do the following wherever you want a Restart link:

    <a class="internalLink restartLink">Reset</a>
    That will open the standard restart confirmation dialog.


    nowherecity24 wrote:

    I know lots of you use sugarcube but as it puts a menu to the left I don't have the ability to play with that.


    Of course you do.  The code/CSS you're using simply was not written to natively support SugarCube.

    (I'm not suggesting you switch to SugarCube.  Use whichever format you prefer.  I just wanted to point out that SugarCube isn't really less malleable, let's say, than the vanilla headers.)


    nowherecity24 wrote:

    From your posts is appears I may as well just put all the variable inits back in the start passage as that works.
    Is there any benefit to using StoryInit in my case?


    Please do not do that.  If you use the code I gave above, then putting your $variable initialization in StoryInit, where it belongs, costs you nothing, and you'll be doing the right thing.

    Simply linking back to the Start passage is the completely wrong way to restart a story/game.  Yes, if you put your $variable initialization in Start, then going back there will reinitialize the $variables, however, none of the rest of the story state will be reset.  Players will be caught in a situation where some of the story state has been reset and some has not (largely, the history stack will never get reset).  [b][i]I strongly suggest that you do not do that.[/b]
Sign In or Register to comment.