I have a widget, “skillxp” that will always take 2 Arguments like following: <<skillxp $Strength 2>>
My question is if I already have _args == $Strength, how can I parse its Value into a Set Marco
as <<set _args += _args>> will only overwrite _Args 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.
/* Assuming $args equals something like "$Strength", and both $Strength & $args contain numbers... */
<<run State.setVar($args, State.getVar($args) + $args) >>