generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Covert String into math

Previous Thread :: Next Thread 
johnhugh is not online. 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 is not online. 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 is not online. 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 is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
26 Feb 2013 06:02 PM
so evaluate does math in strings? @.@
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
26 Feb 2013 06:05 PM
No, loadstring does.
Report Abuse
johnhugh is not online. 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 is not online. 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 is not online. johnhugh
Joined: 26 Mar 2009
Total Posts: 1971
26 Feb 2013 06:07 PM
oh latepost
lemme try it
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
26 Feb 2013 07:14 PM
ogm nubs


tonumber("1 + 4") --> 5
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
26 Feb 2013 07:17 PM
lolno
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
26 Feb 2013 07:53 PM
> print(tonumber("5 + 5"))
nil
Report Abuse
thecaptain97 is not online. thecaptain97
Joined: 17 Jun 2010
Total Posts: 4987
26 Feb 2013 08:45 PM
print(loadstring(YO MATH)())
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image