Howdy, Stranger!

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

Update health stats live as hooks are clicked?

edited March 2016 in Help! with 2.0
At the head of each passage, I have a very simple health count:
Health: $health

The way my passages are written, each sentence is a clickable hook that then reveals the next sentence:
[The knight stabs you!]<stab1| (click: ?stab1)[[He stabs again!]<stab2|] (click: ?stab2)[[And again!]<stab3|]

Is there some way to make certain hooks, when clicked, incrementally lower the $health value, have the $health count at the head of the passage update live, AND reveal the next hook?

Comments

  • edited March 2016
    So I actually got somewhere with this! But not without a few problems Here's what I have:
    (live:0.1s)[
    (if: $ohno is true)[(set: $health to $health - 10) (stop:) Health: $health]
    (else:)[Health: $health]
    ]
    

    With the following code for the hook that triggers it:
    [The knight stabs you!]<stab1| (click: ?stab1)[[He stabs again!]<stab2| (set: $ohno to true)] (click: ?stab2)[[And again!]<stab3|]
    

    The problem I have now is that all links in the passage prior to these flash intermittently (no doubt at the speed of 0.1s) which looks crazy thanks to my hover link styling, and also makes them hard to actually click. Is there a way to avoid this? I'm presuming some placement of (stop:), but I'm not sure where.

    Oh! And I'm using Harlowe here.
  • re: Updating the health count displayed on screen.

    You can use a combination of a named hook and a (replace:) macro to do this. The following example decreases the health value each time you click on the Decrease health link:
    (set: $health to 100)
    
    health: [$health]<health|
    
    (link-repeat: "Decrease health")[
    	(set: $health to it - 10)
    	(replace: ?health)[$health]
    ]
    

    The following is one possible way to implement your multi stabbing Knight, it uses an $attack variable to determine which link to show after the first one.
    (set: $health to 100)
    (set: $attack to 1)
    
    health: [$health]<health|
    
    |knight>[(link-repeat: "[The knight stabs you!]<label|")[
    	(set: $attack to it + 1)
    	(if: $attack is 2)[
    		(set: $health to it - 20)
    		(replace: ?label)[He stabs again!]
    	]
    	(else-if: $attack is 3)[
    		(set: $health to it - 15)
    		(replace: ?label)[And again!]
    	]
    	(else-if: $attack is 4)[
    		(set: $health to it - 15)
    		(replace: ?knight)[The knight is too exhausted to stab you again]
    	]
    	(replace: ?health)[$health]
    ]]
    

    note: Both of the above example include indents and extra line-breaks to make them more readable, those indents and extra line-breaks can be safely removed.
Sign In or Register to comment.