ViRuZGamiing Posted January 9, 2016 Share Posted January 9, 2016 Hey guys, small question I'm using a tonumber() on a string which contains a number between 0 and 1 (example. 0.48) Is it possible that it makes it 0 and not 0.48 becuase I'm getting an error that I'm compairing nil to a number which tonumber's return being the nil. I've output the string and gave me the number, without tonumber() I get trying to compaire string with number. Kind regards, Billy Link to comment
ViRuZGamiing Posted January 9, 2016 Author Share Posted January 9, 2016 LUA: outputServerLog(regenmmPerUur) if (regenmmPerUur < 1) then Console: [12:32:06] 0.252 [12:32:06] ERROR: xml\server.lua:13: attempt to compare string with number When tonumber() is added, Console: [12:34:13] ERROR: xml\server.lua:14: attempt to compare string with number Link to comment
Revolt Posted January 9, 2016 Share Posted January 9, 2016 tonumber(..) should work. You see that the error line is not anymore on the 13th line when you implement it? Link to comment
ViRuZGamiing Posted January 9, 2016 Author Share Posted January 9, 2016 That's because then tonumber() is added lol *facepalm* outputServerLog(regenmmPerUur) tonumber(regenmmPerUur) if (regenmmPerUur < 1) then Link to comment
Revolt Posted January 9, 2016 Share Posted January 9, 2016 outputServerLog(regenmmPerUur) if (tonumber(regenmmPerUur) < 1) then It should be implemented like this. Link to comment
ViRuZGamiing Posted January 9, 2016 Author Share Posted January 9, 2016 OMG now I feel bad for my retardness, this would work to right? regenmmPerUur = tonumber(regenmmPerUur) Link to comment
Revolt Posted January 9, 2016 Share Posted January 9, 2016 Yes. BTW, it is normal that it confuses people, since they cannot know whether tonumber(..)'s arguments are passed by reference or value. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now