0 votes
by (200 points)
edited by

what i am now trying to use link replace for does not seem to work.

<<linkreplace "bag">><<include [[bag]]>><</linkreplace>>

which points to the passage [[bag]]. this is what passage [[bag]] looks like,

you pickup the old worn bag
<<set $bag to true>>

it shows the text but does not run the code inside the passage. then i tried running the code inside of link replace such as this

<<linkreplace "bag">><<set $bag to true>> you picked up the bag<</linkreplace>>

also did not work.

the varible is set to [] in the story init as shown

<<set $Bag= []>>

the varible bag is used as if statment to show if a link is show in the StoryMenu

<<if $bag is true>>[[Inventory]]<<else>><<endif>>

when i set it outside of the linkreplace the code works.

2 Answers

0 votes
by (68.6k points)
selected by
 
Best answer

You have a few issues:

  1. You're misspelling the variable.  You say that you initialize $Bag in the StoryInit special passage, but then show that you're attempting to use it as $bag elsewhere.  Those two are not the same, capitalization matters.
  2. You're doing bizarre things with its type.  You say you initialize it to an empty array in the StoryInit special passage, but then you attempt to use it as a boolean elsewhere, so you should initialize it as a boolean (based on your example usage, to boolean false).
  3. The entire page is usually not updated unless passage navigation happens.  Thus, using one of the interactive macros (e.g. <<linkreplace>>) within a passage will not cause the entire page to be updated.  Meaning, the variable is being changed fine when the link is activated, but the area of the UI bar that displays the StoryMenu special passage won't be automatically updated until passage navigation occurs.

Suggestions:

Initialize $bag (not $Bag) in the StoryInit special passage to boolean false (not to an empty array):

<<set $bag to false>>

Then change your bag passage to something like the following:

you pickup the old worn bag
<<set $bag to true>><<run UIBar.setStoryElements()>>

The call to <<run UIBar.setStoryElements()>> will cause the UI bar's various special passage display areas to be immediately updated.

0 votes
by (159k points)

I believe this was answered within your previous question.

by (200 points)
yes i stopped using click but it does not solve the problem of the code inside of the link not working and that when it is using the include it does not run the code that is inside the passage pointed to by the replace.
by (159k points)

The <<set>> macro within the bag passage is changing the value of the $bag variable, and the example I provided for your other question proves it by updating the page with that new value.

...