0 votes
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
by (44.7k 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

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

...