How do I change math equation from text variable to number

Get help using Construct 2

Post » Fri Mar 31, 2017 10:21 pm

Hello!
If I have a text variable that looks for example like this: "5+7+2*8", is there any way of it calculating the values of that, and then making the answer a number variable? So in the end I would get a number variable with the value of 28.

Any help would be greatly appreciated
Regards,
Kriss
B
3
Posts: 10
Reputation: 195

Post » Fri Mar 31, 2017 10:30 pm

Browser.ExecJS("eval('" & yourString & "');")

I think that will return a string with the evaluated value. And then you can do:

Browser.ExecJS("!isNaN(""" & value & """);")=1?float(value)%1<>0?float(value):int(value):value

which will give you it as either a float,int,or string if it isn't NaN.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Fri Mar 31, 2017 10:38 pm

Prominent wrote:Browser.ExecJS("eval('" & yourString & "');")

I think that will return a string with the evaluated value. And then you can do:

Browser.ExecJS("!isNaN(""" & value & """);")=1?float(value)%1<>0?float(value):int(value):value

which will give you it as either a float,int,or string if it isn't NaN.


This was extremely helpful, thank you so much! It wouldve taken me ages to research that. Thanks a lot :)
B
3
Posts: 10
Reputation: 195


Return to How do I....?

Who is online

Users browsing this forum: farsen and 23 guests