crismar Posted April 15, 2014 Posted April 15, 2014 Howdy, I have this function (trying to make a crafting system for MTA DaYz from scratch) and I want to check if the player has the necessary materials. The problem is: initially, getElementData returned 'false' (boolean) if the player didn't have the item. Now, I used 'tonumber' and it returns 'nil'. Is it possible to convert 'nil' or 'false' to a integer value (0) ? function craftCheck(thePlayer) local craftPickX, craftPickY = guiGridListGetSelectedItem(craftItems) if craftPickX == 0 then guiSetEnabled(craftGo, false) guiSetText(craftReq, "- Lee Enfield [x1]\n- Empty Soda Cans [x3]") guiSetText(craftName, "Item: CZ-550") guiSetText(craftQ, "Cantitate: 1") if tonumber(getElementData(thePlayer, "Lee Enfield")) >= 1 and tonumber(getElementData(thePlayer, "Empty Soda Cans")) >= 3 then guiSetEnabled(craftGo, true) end end end Debugscript keeps returning this error: attempt to compare number with nil On this line: if tonumber(getElementData(thePlayer, "Lee Enfield")) >= 1 and tonumber(getElementData(thePlayer, "Empty Soda Cans")) >= 3 then Ideas ? Contact me if you are looking for a Web Developer. 3rd of October 2014 - Founder of RomaniaZ
JR10 Posted April 15, 2014 Posted April 15, 2014 You can use 'or' to assign a different value if it returns false/nil. This will return either a number or 0 tonumber(getElementData(thePlayer, "Lee Enfield")) or 0 Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
crismar Posted April 15, 2014 Author Posted April 15, 2014 You can use 'or' to assign a different value if it returns false/nil.This will return either a number or 0 tonumber(getElementData(thePlayer, "Lee Enfield")) or 0 Cheers man Contact me if you are looking for a Web Developer. 3rd of October 2014 - Founder of RomaniaZ
Recommended Posts