Jump to content

Error in setElementData - attempt to compare boolean with number


lucasds

Recommended Posts

function collectLeite(thePlayer)
    if getElementType(thePlayer) == "player" then
        if getElementData(thePlayer,"MilkBuckets") <= 10 then
            setElementData(thePlayer,"MilkBuckets", (getElementData(thePlayer,"MilkBuckets")) + 1)
            outputChatBox("#727272You have collected #ffff00 " ..(getElementData(thePlayer,"MilkBuckets")).. "/10 Milk Buckets", thePlayer, 255, 255, 255, true)
        else
            outputChatBox("#727272You already have 10/10 Buckets of Milk", thePlayer, 255, 255, 255, true)
        end
    end
end
addCommandHandler( "collect", collectLeite )

Error script.lua:3 attempt to compare boolean with number

Edited by LucasDSNL
Link to comment
  • Moderators

function collectLeite(thePlayer)
	if getElementType(thePlayer) == "player" then
		local g_MilkBuckets = tonumber( getElementData(thePlayer,"MilkBuckets") ) or 0
		if type(g_MilkBuckets) ~= "number" then return end
		
		if g_MilkBuckets < 10 then
		
			setElementData(thePlayer,"MilkBuckets", g_MilkBuckets + 1)
			outputChatBox("#727272You have collected #ffff00 " ..tostring((g_MilkBuckets + 1)).. "/10 Milk Buckets", thePlayer, 255, 255, 255, true)
		elseif g_MilkBuckets == 10 then
		
			outputChatBox("#727272You already have 10/10 Buckets of Milk", thePlayer, 255, 255, 255, true)
		else
		
			outputChatBox( "Unknown error", thePlayer, 255, 0, 0 )
		end
	end
end
addCommandHandler( "collect", collectLeite )

@LucasDSNL

Link to comment

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