I'm having something of a strange issue that I can't seem to wrap my head around. Here's the basic scenario of what I'm building:
- I have multiple characters, and each one has a designated array that contains their stat variables (i.e. stealth, speed, wounds, etc.). I've made it so that the "wound" stat affects the other stats around it (i.e. speed = it - wound). All of these stats are defined in a header passage called "party_var". For example:
<!-- Korin -->
(set: $klock to 9-$kwound)
(set: $kstealth to 6-$kwound)
(set: $kcombat to 5-$kwound)
(set: $kspeed to 6-$kwound)
(set: $k_stats to (a:$klock,$kstealth,$kcombat,$kspeed, $kwound))
- In this story, I also have "roles" that each character can play, depending on the player's choice earlier on. So for example, Korin has been chosen to be the 'Watcher' for the mission. There is code in "party_var" to account for this, like so:
(if: $watcher is 'Korin')[
(set: $watcher_stats to $k_stats)
(set: $kwound to $wwound)]
- As you can see, I'm setting the character's stats to be equal to the "role" stats. This way, I can write the story and the character who is present in various scenarios can be different, depending on player choice.
I've been trying to implement the scenario where the character gets injured by -2. The moment it happens, I put a simple line like this:
(set: $wwound to it + $injury)
so that the "wwound" variable gets passed to the "kwound" variable, which then affects all the other stats in that character's array accordingly. (I know, the naming is confusing...)
The problem arises because if I put a (print: watcher_stats) command on the next passage after the injury happens, it displays (9,6,5,6,0) - basically as though the injury has not been detected by my code. However, if I add another link to another passage afterwards, then it prints the correct stats: (7,4,3,4,2). I've also noticed I can "workaround" it by adding a (display:"party_var") at the top of the passage immediately after the injury happens.
Basically, it seems that my code only works after I call the setter variables (i.e. "party_var") twice - either by having the user click through two passages, or by displaying "party_var" again after it's already been called as a Header. Is there something in the way Harlowe is reading my variables that I don't understand, and is there a way for me to avoid this/implement this in a better way? It seems like it would be very clunky to have to recall "party_var" with every passage, on top of already calling it as a header.
Thanks and any help is appreciated!