Greetings
This is using Twine 2.0 with Sugarcube story format.
My game has buttons for entering inventoryScreen, charScreen, travelScreen, from any passage where it's allowable. After visiting the passage and reading the information presented there, at the end there is <<return>> button to return.
I've been trying to get around the loop that is created when, say, from inventoryScreen we would have clicked charScreen.
I'd done so already with simply disabling StoryMenu (holding the buttons) when on inventoryScreen passage and the others. But I require additional functionality on these passages now, and <<return>> and the loop 'bug' that comes with it is making it impossible for me.
So, I came up with this (for debugging whether it even works):
<<set $lastVisitedPassage = previous()>>
<<if $lastVisitedPassage == "ScreenMenu" || "travelScreen" || "inventoryScreen" || "charScreen">>
<<print "result 1">>
<<print previous()>>
<<else>>
<<print "result 2">>
<<print previous()>>
<</if>>
and with this
<<set $lastVisitedPassage = previous()>>
<<if $lastVisitedPassage == ("ScreenMenu" || "travelScreen" || "inventoryScreen" || "charScreen")>>
<<print "result 1">>
<<print previous()>>
<<else>>
<<print "result 2">>
<<print previous()>>
<</if>>
The first ALWAYS renders the result 1, the second ALWAYS the result 2. If I change == into != the situation get's reversed, but still always.
By always I mean no matter if print previous() shows any of the passageTitles I want to exclude or a random like desertVillage that I made.
How is that even possible? Of that I am very curious, if not frustrated with.
Most importantly, how to make it work? Or how to make another way of circumventing the <<return>> loop bug without disabling the possibility for the player to enter the inventoryScreen and other passages from any point in the game world?
Also, I'd tried changing the StoryMenu special passage to turn the buttons into setter links, like so:
[[Inventory->inventoryScreen][set $lastVisitedPassage = previous()]]
but an technical error pops up.
Best Regards!
Comments
Also I found a way to refresh without linking, through
Thanks to TheMadExile for that.
You have a spurious set word in your setter. It should look something like the following:
...a spurious set word. I literally KNOW I am not supposed to put it there, yet I completely forgot about it a couple of hours ago and now again. Good job brain.
So, in both cases my stupidity was the problem. Your answers are 100% correct and problem solving. I thank you for your time and help.
The usual way to resolve this particular issue in SugarCube v1 is to use a task and passage tags. For example, you'd put something like the following in your Story JavaScript to setup the task which records the last non-inventory/menu/etc passage: Then you'd tag all of the inventory/menu passages with the specified tag (noreturn in the above example).
To return to the recorded passage, from however deep within the invetory/menus, you'd simply do something like the following:
I shall think on it and try tomorrow, my head hurts from working with twine since morning.