I have a widget, “skillxp” that will always take 2 Arguments like following: <<skillxp $Strength 2>>
My question is if I already have _args[0] == $Strength, how can I parse its Value into a Set Marco
as <<set _args[0] += _args[1]>> will only overwrite _Args[0] to be 2, what I wish to achieve is: <<set $strength += 2>>
Normal I would do this by a Switch statement like:
I went looking for the answer to this same question a few weeks ago and all I found was the suggestion to use the “Stupid Print Trick” to do it, so I was like “well, forget that, then.” I’m very glad to know there’s a more elegant alternative!
The State.getVar() and State.setVar() functions are what SugarCube uses itself within the code of macros like <<textbox>> that take a String Representation of a variable name ("$strength") as their receiverName argument.
<<widget "skillxp">>
/* Assuming $args[0] equals something like "$Strength", and both $Strength & $args[1] contain numbers... */
<<run State.setVar($args[0], State.getVar($args[0]) + $args[1]) >>
<</widget>>