0 votes
asked by (160 points)

I am currently using ChapelR's Simple Inventory system. I have setup links in the StoryCaption to display an inventory passage. My inventory passage has a "menu" tag and I'm using this code in PassageHeader for my back button:

<<if !tags().includes("menu")>>
	<<set $current_scene = passage()>>
<</if>>

The back button:

[[Close|$current_scene]]

This however, reruns any code in the passage (my specific problems, right now, is a <<pickup>> macro from the Simple Inventory macros and dice rolls on passage load). I want to avoid this but I'm not sure of the best way to go about this. The inventory passage is used to modify equipment.

Is there also a way to add links to the StoryCaption/Menu mid-story?

Thanks in advance.

1 Answer

+1 vote
answered by (18.6k points)
selected by
 
Best answer

Actually, for your back button you can probably just use the return macro, which does the same thing.

As for preventing re-triggering code, I just created a JavaScript function that told me whether I got there from my inventory screen or not.  So put this in your JavaScript section:

window.Fresh = function () {
	return (lastVisited("Menu") != 1);
};

Then you can just wrap any code in your passage that you only want executed once inside "<<if Fresh()>>...<</if>>".

As for adding links to the StoryCaption or whatever mid-story, the easiest way to do this is to have the display of the link controlled by some variable, and only show those links when that variable is set to "true".

Hope that helps!  smiley

commented by (160 points)

Actually, for your back button you can probably just use the return macro, which does the same thing.

Sorry, forgot to mention that I'll be adding other menu passages, so my back button is to avoid looping.

Thank you very much! Your code works great. smiley

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...