Howdy, Stranger!

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

[Harlowe] Restart function?

I'm trying to add a "Restart" button to my game, but the problem is it doesn't work properly with my save system. I have
{
(save-game: "Save")
}

at the bottom of each passage to act as an autosave function, and my first passage is this
(if: (saved-games:) contains "Save")[
	(load-game: "Save")
](else:)[
	(goto: "Intro")
]

I also have a button in my header that contains this
{
(link: "Restart")[(confirm: "Are you sure?")[(goto: "Intro")]]

The problem is that all the values are still saved when restarting, and the links you previously clicked are purple. The only solution I can think of is to have a unique save file for the intro screen that the Restart link loads that contains no previous data. If there's an easier way to restart the game however, I'd much rather use that, since the load feels clumsy.

Comments

  • edited January 2016
    There are a number of ways to simulate restarting the story/game, each with their own pros and cons but I think the simplest is to use Javascript to reload the current URL.
    (link: "Reload URL")[<script>document.location.reload();</script>]
    

    re: automatically returning to last passage viewed.
    You may want to give the reader a yes/no choice before automatically using (load-game: "Save") to return the reader to the last passage they viewed or else the reader wont be able to replay your story/game from the start without either using your restart option or clearing their web-browser's cache.
  • The game is running as an .exe through a webkit, I'm not entirely sure if that has a cache or not.

    Either way, I managed to fix the restart function using a bunch of save cheats.

    This is at the bottom of my Intro page:
    {
    (save-game: "GameStart")
    }
    {
    (save-game: "Save")
    }
    

    This is the code for the start-up screen:
    (if: (saved-games:) contains "Save")[
    	(load-game: "Save")
    ](else:)[
    	(go-to: "Intro")
    ]
    

    This is the code for the restart button (which is always in my header):
    {
    (link: "Restart")[(confirm: "Are you sure?")[(load-game: "GameStart")]]
    }
    

    Basically when you click restart, it loads the GameStart and then immediately saves over the Save file, and everything is working as intended. I haven't encountered any problems with this, even though it feels like a very clumsy way of doing it.

    Thank you for your help anyway! I appreciate your answers as always, they're always very educating and enlightening.
  • greyelf wrote: »
    There are a number of ways to simulate restarting the story/game, each with their own pros and cons but I think the simplest is to use Javascript to reload the current URL.
    (link: "Reload URL")[<script>document.location.reload();</script>]
    

    The actual simplest way is to use the
    (reload:)
    
    macro, for the record.
  • L wrote: »
    The actual simplest way is to use the
    (reload:)
    
    macro, for the record.
    I must be going blind in my old age because I don't know how I missed that, ty @L and sorry @Chalk for misleading you.
  • I couldn't get reload to work properly when I tried to use it
Sign In or Register to comment.