Howdy, Stranger!

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

Updating variables

This is similar to my last post, but is there any easy way to 'refresh' a variable? For example:
$time seconds left.

[Look around the room.]<look|

(click: ?look)[(set: $time to it - 1)(replace: $time)[$time](replace: ?look)[You're in a small storage room. There's a shelf, and a crate.]]
I want to subtract one from $time when you click the link, and I can do the subtraction bit just fine. My problem is that the $time variable still shows the previous number, because it hasn't re-run that part of the code.
The part where I try to replace $time with $time doesn't work, because the replace command only does hooks and text. I'm guessing the solution is close to this, though.
I'm using Harlowe. I can switch to a different format if this feature is only in the more fleshed-out formats, but ideally I would like to stick with Harlowe.

Comments

  • edited August 2016
    When you display/print the value of a variable (eg. $time seconds left) the resulting output has no connection with the original variable, so the output will not automatically change when the value of the variable does.

    Point 2 in my answer to your last question shows how to use a (replace:) macro to update the contents of a named hook which is wrapping the output of a variable, it was why I wrote that example the way I did. *smile*
  • Oh ok, thanks! I thought that when you attach a hook to something, it always makes it clickable. Anyways, it works! Sorry for being a hassle, I'm new to Twine.
  • Psykarp wrote: »
    Sorry for being a hassle, I'm new to Twine.

    Someone who's willing to learn is never a hassle to anyone who's willing to teach.

    That said, I'm gonna hassle everyone here (mostly greyelf).
Sign In or Register to comment.