Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help with (click:) and with an updating variable? Harlowe

Okay so I'm trying to write a fight but I've ran into 2 problems. First I need to find a way that when you click the [attack] hook it refreshes so you can essentially attack again. As you can see I tried to use (click-replace:) but it didn't solve the problem. So pretty much after you click the hook it just turns into text of the word. My second issue is when you attack the $enemyhp variable doesn't update, it just stays at 100, atleast on the page. I also tried to have the $enemyhp variable live on another passage that I would just display but that also didn't work.
(set: $enemyhp to 100)
[attack]<attack|
(click-replace: ?attack)[ (set: $enemyhp to $enemyhp - (random: $weapon-2 , $weapon+2)) [attack]<attack| ]

$enemyhp

Comments

  • 1. When the output for a passage is generated any variables within the passage contents are replaced with the current value of that variable, this is why the output of the $enemyhp line that appears at the end of your example never changes.

    2. Harlowe's Sensor Macros like (click:) and (click-replace:) are single use only, so if you want the hook to be converted into a click-able link again then you have to re-apply the sensor macro again.

    The following consists of two passages:

    1. Attack Logic
    This contain the code to create the attack link, the code that gets run when the link is clicked, the code to updates the displaying of the $enemyhp output and the code that makes the link click-able again.
    {(link: "attack")[
    (set: $enemyhp to it - (random: $weapon - 2 , $weapon + 2))
    (replace: ?hp)[$enemyhp]
    (replace: ?attack)[(display: "Attack Logic")]
    ]}
    
    2. The passage in which the link and enemyhp are shown:
    (set: $enemyhp to 100)
    
    |attack>[(display: "Attack Logic")]
    
    |hp>[$enemyhp]
    
  • I honestly love you greyelf. I'd be so lost without you.
Sign In or Register to comment.