Jump to content

Check if a string are numbers.


Feche1320

Recommended Posts

Hello, I'm making a /flip command, but if he types nothing or just letters, it give me an error on debugscript, so I made this:

if ammount == "nil" then 
outputChatBox("Usage: flip [amount]", source, 46, 154, 254) 
        return 
    end 

And:

if tonumber(ammount) == "nil" then 
outputChatBox("Usage: flip [amount]", source, 46, 154, 254) 
        return 
    end 

But none of them work.

Thanks

Link to comment

-> if ammount == "nil" then

should be like

-> if ammount == nil then

or even like

-> if not ammount then

if tonumber(ammount) == "nil" then 

same way:

if not tonumber(ammount) then 

Means tonumber() can't convert "amount" string into a number, so false is returned and that's what we're checking for using "not".

Link to comment

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...