If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.4.1
Story Format: Sugarcube V2
So I’m trying to transfer code I have in javascript to sugarcube and I was wondering if it’s possible to use a widget in itself kinda like how you would call a function within itself?
I’ve done it, and it works as intended. The goal was to produce a random name from a list, and, if the reader doesn’t like the name, to offer to produce another (another random name, not another reader obviously).
And then call it with <<widget1>> I’d expect it to print “this” repeatedly.
Instead I get Error: <<widget1>>: error within widget code repeating. What have I done wrong?
If the issue is that it is repeating too deeply as you said, how do I limit it? (Now that I look more closely I see the “too much recursion” error at the very end).
First you need to determine when you want the action being done within the widget to stop being done.
Then you add a condition check (like the following) that will stop the widget being call recursively
eg. do you only want that action to be done a specific number of times? If so you could use a counter variable to determine when to stop calling the widget again.
note: you need to pre-initialise this counter variable sometime prior calling the widget the first time.