0 votes
by (350 points)
I am running into two problems. The first involves a header passage. I am looking to place a variable for a health bar in a header passage. When I do this, the health variable is on a one passage delay. I figure this is due to the header code being run first, while the (set:) macro is being run second in the passage text. Is there a way I can force the header to update after the (set:) macro has run in the passage text?

 

The second problem is similar, but with the footer. The footer will display the health bar accurately. I am assuming this is because the (set:) macro is running first and the footer is being run second. However, when I place an (if:) statement in the footer (if: $health is 0)[goto: "death"] the passage continuously runs the footer code in a loop and never progresses to the "death" passage. Is there a way to fix this?

 

I am using Harlowe 3.0.2, and the problem also occurs in Harlowe 2.1.0

 

I appreciate the help!

1 Answer

+2 votes
by (159k points)

1. Dynamically updating existing sections of the current page.

You can use a named hook to mark the area you want to dynamically update, and a (replace:) macro to perform the update.

1a. Mark the area you want to update in your header tagged special passage.

health: [$health]<health|

1b. Update the contents of the named hook after changing the value of the associated variable within your Passage.

(set: $health to it + 1)
(replace: ?health)[$health]

note: You can name the named hook whatever makes sense to you or your project.

2. The looping is occuring because the contents of that footer tagged special passage is also being added to the bottom of your death passage, which results in the (goto:) macro being called over and over.

This issue is simply fixed by changing the existing condition in your footer tagged special passage to only be evaluated for passages other than your death one. You can use the (passage:) macro to determine the name of the current passage.

(if: (passage:)'s name is not "death" and $health is 0)[(goto: "death")]

 

...