Using multiple arguments in a widget to reuse code not working the way i expect

Twine Version: 2.71
[also choose a Story Format tag above]
Maybe i am making it too complicated but coming from other languages this feels a little more natural to me.

I want to pass information with a widget call so that i can use the code in the widget repeatedly without pasting it repeatedly. There are three things that vary depending on progress in the event but otherwise it is the same

so i am passing <<progress “20” “helpone” “repeatone”>> which should pass _args[0] as 20, _args[1] as helpone and _args[2] as repeatone

ultimately this should uncomplicate large code blocks and make use of the same code multiple times.

The end code it puts the args into is

<<widget "progress">>
<<set _progress to $work + $effort>><<set _dccheck to random(1,_args[0])>><<if _progress > _dccheck>><<_args[1]>><<elseif _dccheck - _progress <=2>><<_args[2]>><<else>>
<<NextPassage>><</if>>
<</widget>>

the end result being the random number is between 1 and 20, the DC Check if successful will progress the event to helpone widget and a close failure will result in a repeat of the work that just happened in a modified version.

I get an error that says

Error: <<help>>: error within widget code (Error: <<progress>>: error within widget code (Error: <<set>>: bad evaluation: missing ) after argument list))

Any idea what i am doing wrong?

oh i also tried searching forum and found something similar so i tried it and still got the error

<<widget "progress">>
<<set $dc = '<<' +_args[0] + '>>' >>
<<set _progress to $work + $effort>><<set _dccheck to random(1, $dc>><<if _progress > _dccheck>><<_args[1]>><<elseif _dccheck - _progress <=2>><<_args[2]>><<else>>
<<NextPassage>><</if>>
<</widget>>

If the “20” argument is meant to be an actual Number then it shouldn’t be wrapped in quotes. By wrapping it in quotes you’re stating that the data-type of that value is a String, not a Number.

Try doing the following instead.

<<progress 20 "helpone" "repeatone">>
1 Like

While @Greyelf is correct that you should use an actual number, your error is because you are missing the ) after your random().

However, you are also explicitly turning $dc into a string, <<20>> which you definitely can’t use in a random(). Not sure what your intent was there (trying to print it, I imagine?), but it definitely isn’t going to work, even if you pass 20 into your widget instead of "20".

The correct code would be:

<<widget "progress">>
  <<set _progress to $work + $effort>>
  <<set _dccheck to random(1, _args[0])>>
  <<if _progress > _dccheck>><<_args[1]>><<elseif _dccheck - _progress <=2>><<_args[2]>><<else>><<NextPassage>><</if>>
<</widget>>