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?

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

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.

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

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.

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

  • 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 
  

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

This.

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

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