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:

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

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

Produces
02468
13579

etc. What would I need to be doing to get:
0123456789
0123456789
?
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!