Howdy, Stranger!

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

(Harlowe) Performing math with random variables

(click: "crumbs")[''You collect some crumbs!''(set: $Cdrop to (random: 1,4))(set: $Crumbs to "$Crumbs + $Cdrop")]
As you can see, I am trying to make a random drop system that adds to the overall displayed variable. My issue is that it runs the addition function infinitely. I tried setting it to a single number instead of random, but i had the same issue. $Crumbs is set to 0, so I am not sure what I am doing wrong.

Comments

  • When you display the value contain within a variable on the page, it is a copy of the value that is displayed and there is no connection between the displayed copy and the original variable.

    Remove the quotes around your assignment:
    (set: $Crumbs to $Crumbs + $Cdrop)
    
    You can use the combination of a named hook and a (replace:) macro to update the value displayed on the page:
    (set: $crumbs to 0)
    
    Number of crumbs: [$crumbs]<count|
    
    (link: "crumbs")[
    	(set: $crumbs to it + (random: 1,4))
    	(replace: ?count)[$crumbs]
    ]
    
  • greyelf wrote: »
    When you display the value contain within a variable on the page, it is a copy of the value that is displayed and there is no connection between the displayed copy and the original variable.

    Remove the quotes around your assignment:
    (set: $Crumbs to $Crumbs + $Cdrop)
    
    You can use the combination of a named hook and a (replace:) macro to update the value displayed on the page:
    (set: $crumbs to 0)
    
    Number of crumbs: [$crumbs]<count|
    
    (link: "crumbs")[
    	(set: $crumbs to it + (random: 1,4))
    	(replace: ?count)[$crumbs]
    ]
    
    Thank you so much! It updates in the main HUD, so running (replace:) isnt needed
Sign In or Register to comment.