Jump to content

Item LUA Error


Recommended Posts

so i added a food item to my mod and whenever i try to spawn it in this happenswha..thumb.PNG.50dcbb9e2f40d9b3be400b397582895e.PNG

i read the error screen above and even checked the code over and over but i still didnt understand the problem

here's the whole code if anyone wishes to see it

local Assets =
{
	Asset("ANIM", "anim/candyhorns.zip"),
    Asset("ATLAS", "images/inventoryimages/candyhorns.xml"),
	Asset("IMAGE", "images/inventoryimages/candyhorns.tex"),
}

local function fn()
	
	local inst = CreateEntity()
	
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("candyhorns")
    inst.AnimState:SetBuild("candyhorns")
    inst.AnimState:PlayAnimation("idle")

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/candyhorns.xml"

	inst:AddComponent("inspectable")
	
	inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM
	
    inst:AddComponent("edible")
    inst.components.edible.healthvalue = 500
    inst.components.edible.hungervalue = 500
    inst.components.edible.sanityvalue = 500
    inst.components.edible.foodtype = "MEAT"
    inst.components.edible:SetOnEatenFn(oneaten)
    
    return inst
end

return Prefab("common/inventory/candyhorns", fn, Assets)

can someone please help?

Link to comment
Share on other sites

Warning syntax errors maybe present,  few lines of codes missing:

 

inst.entity:SetPristine() --after inst.animstate:playanimation or you'll get some really  strange errors
  
 if not TheWorld.ismastersim then --this is used heavily in dst code
        return inst
    end

 

inst.components.edible.foodtype = FOODTYPE.MEAT --just incase if item type is wrong in the code above

 

and yeah rons0n is right about the missing function oneaten is not declared so remove it.

Link to comment
Share on other sites

Just now, rons0n said:

    inst.components.edible:SetOnEatenFn(oneaten)

What does this do? You didnt specify what happens in the code when the item is eaten.

You can delete that line if you dont need it. 

i was copying from another mod i knew that had an edible item, and i found that set of code, so i added oneaten because i didnt know what it did

thats why i added it

i got rid of it now and it works

Just now, K1NGT1GER609 said:

Warning syntax errors maybe present,  few lines of codes missing:

 

inst.entity:SetPristine() --after inst.animstate:playanimation or you'll get some really  strange errors
  
 if not TheWorld.ismastersim then --this is used heavily in dst code
        return inst
    end

 

inst.components.edible.foodtype = FOODTYPE.MEAT --just incase if item type is wrong in the code above

yes thank you! the item works now

thanks for the help you two

Link to comment
Share on other sites

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
 Share

×
  • Create New...