Hi all!
Is it possible to have the contents of a string variable used as a calculation? For example if I had a string that read "1+3+4" is there any way that string could be processed to express "8"?
My string is generated through a combination of RegexReplace and replace scripts (
replace(RegexReplace(testObject.inputVarOne,"([[a-zA-Z][a-zA-Z0-9]*,?)","g",""),",","+")[/code:yvh8elm2]) eventually turning a string of values into something more akin to a mathematical formula like the one shown above. Is there a way to turn that outputted string value into a calculation that construct2 can read 8 instead of 1+3+4? ---- update Here is what I have attempted so far: I have created a string variable and set it to the above formula, meaning the string value is literally "1+2+3" I created a second, number variable and set it to the test variable I just made, and unfortunately instead of outputting "6" as expected, it simply output "1". Can anyone offer any insight?
for your particular example, you will do:
local static var sum = 0
For
from 0 to tokencount("1+2+4","+") >> Add to: sum: int(tokenat("1+2+4",loopindex,"+")
from 0 to tokencount("1+2+4","+")
>> Add to: sum: int(tokenat("1+2+4",loopindex,"+")
Develop games in your browser. Powerful, performant & highly capable.
for your particular example, you will do: local static var sum = 0 For >> from 0 to tokencount("1+2+4","+") >>>> Add to: sum: int(tokenat("1+2+4",loopindex,"+")
>> from 0 to tokencount("1+2+4","+")
>>>> Add to: sum: int(tokenat("1+2+4",loopindex,"+")
Thank you! This worked perfectly