0 votes
by (160 points)

In my code, I have a notification in the footer that is updated on each new passage, and I like to run information to the footer through a simple 

<div id="footer"><span id="notifications"></span></div>

Which is well and good, especially when using the <<link>> macro, as such.

<<if $storageKit isnot 1>>
<span id="medStorageSearch">There is a First Aid Kit on the wall.
<<link "Take it.">>
	<<addToInv "First Aid Kit">>
	<<set $storageKit to 1>>
	<<append "#notifications">><span style="color:lime">
	<p class="css-typing">First Aid Kit acquired. <br>
	</p></span><</append>><<replace "#medStorageSearch">>

However, if I omit the <<link>> and simply try to append the notification to the footer, it does not appear and I suspect that it may be that the passage is not updating. Outputs and value changes work, but the display does not update. Any suggestions?

To reiterate, I simply want to be able to use the following code in a passage without requiring a click from the user:

<<append "#notifications">><span style="color:lime">
<p class="css-typing">First Aid Kit acquired. <br>


1 Answer

+1 vote
by (63.1k points)
selected by
Best answer

As noted in the documentation, you can't use the DOM macros in passage code to update that passage's own elements. Link

WARNING: All DOM macros require the elements to be manipulated to be on the page. As a consequence, you cannot use them directly within a passage to modify elements within said passage, since the elements they are targeting are still rendering and not yet on the page. You must, generally, use them with a interactive macro (e.g. <<link>>) or within the PassageDone special passage. Elements which are already part of the page, on the other hand, present no issues.

PassageHeader and PassageFooter are a part of the passage element, so these rules still apply to them. You can use a <<timed>> macro and set it to 100ms or so to get around this limitation instead of using PassageDone or interaction. 

by (160 points)
Very good, thank you!
by (63.1k points)

As a side note, in my set of custom macros, there are insert macros that address this problem specifically without needing to play with timing. It's a simple solution either way, so YMMV.