How to make a player go back to their last visited passage without undoing all actions that took place?

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.15
Story Format: Harlow 3.2.3
I am making an RPG, and I have added multiple stores where the player can buy items. They can only buy things if they have enough of a variable. After the player buys something, I would like them to be sent back to the most recent passage they visited. However, you can’t use the undo button because that undos your purchase. I want to make it so the player goes back to the passage they were just at without undoing the action they made. How would I do this? This is really urgent because my game depends on buying and crafting items, and without this I can’t continue creating the game.

You didn’t specify your story format, and the exact solution depends on that.

If you’re using Sugarcube 2 (which I think is the best fit for an RPG), you can use the <<return>> macro, which forwards the story to the previous passage (forwarding means it doesn’t undo the history). So, if you put <<return "Back">> in your store passage, this will create a link with the text “Back”, which will redirect you to whichever passage you “entered the store” from.

You can read more about <<return>> in the Sugarcube 2 documentation: SugarCube v2 Documentation

If you’re using Harlowe, or any of the other story formats, the answer will be different though (and, unfortunately, I’m not familiar with those formats).

2 Likes

I would switch to SugarCube 2, but I have gotten so far in the game that switching would totally screw up everything.

So, I figured out the answer with a bit of Googling - apparently, in Harlowe you can use (link-goto: "Back", (history:)'s last) to forward the story to the last visited passage (tested in Harlowe 3.2.3, works the same way Sugarcube’s <<return>> does). (You can, of course, change your link text to something else by replacing “Back” in my example).

2 Likes

Oh Wow! Thanks A Lot!!!

but unfortunately, this can’t keep all the choice you’ve made, all the variables you’ve changed in this passage also changed back.

Is there a way to go back but keep those changes?

Thanks!

The link he gave provides the answer clearly.

The versions that forward to a specific passage are largely unnecessary, as you could simply use a normal link

The code I gave does not change any variables. It works like a standard link to a passage, only it always goes to the previous passage the player visited, and not to the passage name specified within the link.

What could be happening (though I don’t know for sure without seeing your code) is that you’re setting a variable somewhere within the first passage. You didn’t specify if you’re using Harlowe or Sugarcube, so I’ll write in general terms without providing specific code, as the same idea applies to both formats.

Let’s say you have a passage named “Start”, where you set $money to 100. The passage also includes a [[Next]] link. In the “Next” passage, you set $money to 1000 and add a <<return>> / (link-goto: (history:)'s last) link. When you play the game, going to the “Next” passage does set $money to 1000, but as soon as you use the return link, the “Start” passage is displayed, and it sets $money back to 100. The game doesn’t undo the changes to the $money variable, it simply sets it to 100 each time “Start” is displayed.

Is this perhaps what happens in your game?

2 Likes

FYI - The OP did specify that they’re using Harlowe:

and I assume thris00 was continuing to speak about Harlowe.

Oh I’m sorry, should’ve mentioned that was an edit

No problem. I added “Harlowe” as a tag to your thread too. It may not have been mentioned originally, but it should be clear now.

Hi, Agnieszka ,Sorry, my bad,

I mistakenly take your solution as the same as (undo:)

because I actually tried a lot about solutions to this question:

and all turns out to be failure, it seems (undo:) would rewind everything including variables no matter what.

You are right, you solution didn’t change variables and keeps all the choices, and just go back t o previous pages, That’s great !

Thanks a lot

1 Like