Jump to content

tonumber()


Recommended Posts

Posted

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

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

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 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

tonumber(..) should work. You see that the error line is not anymore on the 13th line when you implement it?

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

Posted

That's because then tonumber() is added lol *facepalm*

    outputServerLog(regenmmPerUur) 
    tonumber(regenmmPerUur) 
    if (regenmmPerUur < 1) then 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
outputServerLog(regenmmPerUur) 
if (tonumber(regenmmPerUur) < 1) then 

:lol: It should be implemented like this.

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

Posted

OMG now I feel bad for my retardness, this would work to right?

regenmmPerUur = tonumber(regenmmPerUur) 

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Yes. BTW, it is normal that it confuses people, since they cannot know whether tonumber(..)'s arguments are passed by reference or value.

Need a scripter? Feel free to contact me for inexpensive high-quality service!

Skype username: friedonibot

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...