Jump to content

Simple question


megaman54

Recommended Posts

You mean this?
print( type( 1 ) ) -- print number 

Example:

function main( arg ) 
    if type( arg ) == 'number' then 
        return true 
    end 
    return false 
end 
  
print( main( 1 ) ) --> true  

Wrong. print(type("1")) will return false. Command arguments are always strings, so no matter what player writes, it will give the same results.

Link to comment
print(type("1")) will return false

Nope,wrong.

It return string ,i test it in lua demo.

Command arguments are always strings, so no matter what player writes, it will give the same results.

Yeah,but if player not use arguments in command ( just /some ) we can check it with type function or with condition if ... then ( this is same ).

Example

addCommandHandler( "some", 
    function( soruce,_,a ) 
        if type( a ) == 'string' then 
            outputChatBox( "string" ) 
        else 
            outputChatBox( "WRONG:Use /some and arguments" )        
        end 
    end 
)    

P.S If he need test this in mta:

print( type( "1" ) ) 

Just

outputChatBox( type( "1" ) )  

Link to comment

Oh, i mean, print(main("1")) will print false if we use your "main" function. megaman54 didn't ask for a way to check if an argument exists (in addition, checking the type is useless, just compare the variable to nil). He asked for a way to determine whether the player typed in a number. FatalTerror showed how to do this correctly. Your example is wrong because it doesn't check whether the string contains any numbers.

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