Jump to content

nil with number


Drakath

Recommended Posts

Posted

attempt to compare nil with number

if (tonumber(getPlayerMoney (source)) >= tonumber(cost)) then 

Is it possible that money can be nil? Or is it the cost that is nil?

s.epicrow.com:22003.png

Posted

Debug it.

outputChatBox ( tostring ( cost ) ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted

Cost is nil.

getPlayerMoney can only return nil when the player isn't a player or he has already left the game. But that will give a second error/warning.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
Cost is nil.

getPlayerMoney can only return nil when the player isn't a player or he has already left the game. But that will give a second error/warning.

Cost could be nil.

or something that isn't a int or float.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

I tried debugging it with: outputChatBox ( tostring ( cost ) )

But all results outputted a number just like tonumber(cost)

I'm not sure how do players manage to make this error.

Also when I added this line: if not tonumber(cost) == nil then I couldn't buy it anymore.

s.epicrow.com:22003.png

Posted

Are you sure that you're trying to receive the money of the right person? I've had trouble with this too, but that was because my money was... oh well... 0. ^^" ( without tonumber, this will also give you an error. )

You should try to see what 'source' is:

outputDebugString ( getPlayerName ( source ) ) 

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

  • Moderators
Posted

well if it output always correct, then it should work.

The most secure way would be:

local cost= tonumber(cost) 
local money = getPlayerMoney (source) 
if cost and money then 
    if money >= cost then 
        outputDebugString("works") 
    else 
        outputDebugString("not enough money") 
    end 
else 
    outputDebugString("cost or money do not exist.") 
end 
  

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
local cost = tonumber(cost) or 0 

This.

You want to change everything to free when the price is bugged? :|

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
local cost = tonumber(cost) or 0 

This.

You want to change everything to free when the price is bugged? :|

Oh, right. :D

Well He might be setting the price wrong or something else that its returning nil.

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