Updating variables on the same page as cycling-link?

(I’m using Harlowe 3.3.3)

Hey folks, I’m trying to use cycling-link to do this:

There are many objects in this room, but you are looking at the (cycling-link: bind $thing, "door","crate", "wall"). 

The $thing looks very interesting.

In this example, my intention is that $thing and any other variables I put in the cycling-link will update when the link changes in real time, but this is not the case - instead it only updates when I reload the storylet. Does anyone know how I can get it to update with the cycling link?
Thank you!

The confusion with Twine (in general) is that the passage is not responsive to variable changes after it’s been rendered. What you see, as a player, is a static webpage.

To have the sentence The $thing looks very interesting. be updated, you have to put it in a hook and then re-run the hook when the variable changes.

There are many objects in this room, but you are looking at the (cycling-link: bind $thing, "door","crate", "wall"). 

|update>[The $thing looks very interesting.]

(link-rerun: "UPDATE")[(rerun:?update)]

Now, the issue with cycling links (from my experience) is that I don’t know how to make them run a piece of code in conjunction with binding them to a variable.

One strategy is to make a (live:) macro that repeatedly reruns the |update> hook. It’s not ideal, but will work. I think you can wrangle that up on your own.

Another strategy is to make your own “cycling link” that can also run whatever you need it to do. I’ll look into that and see what I can come up with.

1 Like

Alright, here’s a homegrown cycling link.

(set: _items to (a: "door", "crate", "wall"))
(set: _index to 1)
(set: $thing to _items's _index)

There are many objects in this room, but you are looking at the |cycle>[(link-rerun: "$thing")[{
(if: _index < _items's length)[
	(set: _index to it + 1)
](else:)[
	(set: _index to 1)
]
(set: $thing to _items's _index)
(rerun: ?update)
(rerun: ?cycle)
}]]. 

|update>[The $thing looks very interesting.]

You should be able to read through the logic and make sense of it. If you have any questions about it, let us know.

Edit: One potential problem with this code is that if $thing is already set in another passage, coming back to this logic will reset it to "door". We could add extra logic to account for that, but for now, we’ll leave it at that. A (live:) macro solution wouldn’t have to deal with that though.

1 Like