johnhugh
|
  |
| Joined: 26 Mar 2009 |
| Total Posts: 1971 |
|
|
| 26 Feb 2013 05:52 PM |
equation = "11+1"
so how can i, in end, turn it into an equation and not a string resulting in 12 |
|
|
| Report Abuse |
|
|
Lombardo3
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 271 |
|
|
| 26 Feb 2013 05:56 PM |
meh...
function evaluate(str) return loadstring(str)() end
print(evaluate("1337+1")) |
|
|
| Report Abuse |
|
|
Lombardo3
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 271 |
|
|
| 26 Feb 2013 05:59 PM |
Ups, forgot to return the value
function evaluate(str) return loadstring("return "..str)() end
print(evaluate("1337+1")) |
|
|
| Report Abuse |
|
|
johnhugh
|
  |
| Joined: 26 Mar 2009 |
| Total Posts: 1971 |
|
|
| 26 Feb 2013 06:02 PM |
| so evaluate does math in strings? @.@ |
|
|
| Report Abuse |
|
|
| |
|
johnhugh
|
  |
| Joined: 26 Mar 2009 |
| Total Posts: 1971 |
|
|
| 26 Feb 2013 06:06 PM |
que = "11+1" print(evaulate(equ)) 3: attempt to call nil |
|
|
| Report Abuse |
|
|
Lombardo3
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 271 |
|
|
| 26 Feb 2013 06:07 PM |
| Yeah, is kinda haxy. I just create a function using loadstring and the argument you passed, and append "return " before the parameter, next I call the returned (by loadstring) function and return that (the result of the returned function by loadstring). This just forces lua to evaluate the expression. |
|
|
| Report Abuse |
|
|
johnhugh
|
  |
| Joined: 26 Mar 2009 |
| Total Posts: 1971 |
|
| |
|
|
| 26 Feb 2013 07:14 PM |
ogm nubs
tonumber("1 + 4") --> 5 |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Feb 2013 07:50 PM |
Yes.
http://wiki.roblox.com/index.php/String http://wiki.roblox.com/index.php/Function_Dump/Core_Functions |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2013 07:53 PM |
> print(tonumber("5 + 5")) nil |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2013 08:45 PM |
| print(loadstring(YO MATH)()) |
|
|
| Report Abuse |
|
|