Drakath Posted February 8, 2014 Posted February 8, 2014 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?
Castillo Posted February 8, 2014 Posted February 8, 2014 Debug it. outputChatBox ( tostring ( cost ) ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Moderators IIYAMA Posted February 8, 2014 Moderators Posted February 8, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
xXMADEXx Posted February 9, 2014 Posted February 9, 2014 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. The Ultimate Lua Tutorial! | MTA PHP SDK
Moderators IIYAMA Posted February 9, 2014 Moderators Posted February 9, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Drakath Posted February 9, 2014 Author Posted February 9, 2014 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.
tosfera Posted February 9, 2014 Posted February 9, 2014 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 ) ) If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
Moderators IIYAMA Posted February 9, 2014 Moderators Posted February 9, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Moderators IIYAMA Posted February 9, 2014 Moderators Posted February 9, 2014 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 Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Saml1er Posted February 9, 2014 Posted February 9, 2014 local cost = tonumber(cost) or 0 This. You want to change everything to free when the price is bugged? Oh, right. Well He might be setting the price wrong or something else that its returning nil.
Drakath Posted February 10, 2014 Author Posted February 10, 2014 Well, I received "cost or money do not exist." output a few times but at least there are no more errors. Thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now