SugarCube - variable scope in widget

Hi there,

I’m playing with Twine 2.3.5 and Sugarcube 2.33.2.

I’m trying to get multiple typewriter macros going at the same time on the same passage. But I’m running into a problem because as best I can tell a _temporaryVariable inside a widget is just declared as a _temporaryVariable within the passage. So:

<<widget test>>
<<set _count=0>>
<<repeat 4s>>
<<print _count>><<set _count=_count+1>>

<<timed 2s>><<test>><</timed>>


etc. What would I need to be doing to get:
Do I need to get my head around Macros instead of widgets and use pure javascript? If so how do I avoid the same problem?

Thanks in advance for any help or advice!

1 Like

Yeah, temporary variables are visible everywhere in the current “moment”, regardless whether that’s in a widget or an included passage or whatever. You probably want to wrap a <<capture _count>> around the <<repeat>>?

ah - capture - that’s it. Thanks!