Jump to content

Changing from 'nil' to integer ?


crismar

Recommended Posts

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 ?

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...