Jump to content

Recommended Posts

So I've been messing w and trying to get this sanity boosting item to degrade only when held in your hand, so i gave it the same fuel type as hats and whatnot. i've added the code un onequip and onunequip as well to tell it turn it on and off but now I just get this error:

084f0f2c4cee8ced94388bd6bd7665f7.png

I've included the LUA for the music box if it helps any. I have no idea what this error means 0(

Here's the code, as well:

local function fn(colour)

    local function OnEquip(inst, owner) 
        --owner.AnimState:OverrideSymbol("swap_object", "swap_musicboxs", "purplestaff")
        owner.AnimState:OverrideSymbol("swap_object", "swap_musicbox", "musicbox")
        owner.AnimState:Show("ARM_carry") 
        owner.AnimState:Hide("ARM_normal") 
	end
		
			if inst.components.fueled ~= nil then
			inst.components.fueled:StartConsuming()
		end
end

    local function OnUnequip(inst, owner) 
        owner.AnimState:Hide("ARM_carry") 
        owner.AnimState:Show("ARM_normal") 
    end
	
			if inst.components.fueled ~= nil then
			inst.components.fueled:StopConsuming()
			
		end

local function fn(Sim)

[I saw a user who had a second "end" after the final end listed in this code but when I did that it gave me <eof> expected near end, and then pointed to that line and looking online told me it was too many ends. Since removing it, I just get this error now]

Thank you for taking a look..!

musicbox.lua

Edited by Aibou
solved, updating title

The end is placed at the wrong place so that you a piece of the function is not included, therefore it calls for inst, which is not defined outside the function.

It's always helpful for me to use identation so that you can see where an end or something like that is missing, here in your case the code in the correct form would look like that:

Spoiler

local assets=
{ 
    Asset("ANIM", "anim/musicbox.zip"),
    Asset("ANIM", "anim/swap_musicbox.zip"), 

    Asset("ATLAS", "images/inventoryimages/musicbox.xml"),
    Asset("IMAGE", "images/inventoryimages/musicbox.tex"),
}

local prefabs = 
{
}

local function OnEquip(inst, owner) 
    --owner.AnimState:OverrideSymbol("swap_object", "swap_musicboxs", "purplestaff")
    owner.AnimState:OverrideSymbol("swap_object", "swap_musicbox", "musicbox")
    owner.AnimState:Show("ARM_carry") 
    owner.AnimState:Hide("ARM_normal") 
		
    if inst.components.fueled ~= nil then
        inst.components.fueled:StartConsuming()
    end
end

local function OnUnequip(inst, owner) 
    owner.AnimState:Hide("ARM_carry") 
    owner.AnimState:Show("ARM_normal") 
    if inst.components.fueled ~= nil then
        inst.components.fueled:StopConsuming()
    end
end

local function fn(Sim)
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("musicbox")
    anim:SetBuild("musicbox")
    anim:PlayAnimation("idle")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "musicbox"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/musicbox.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE

    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = FUELTYPE.USAGE
    inst.components.fueled:InitializeFuelLevel(TUNING.TOPHAT_PERISHTIME)
    inst.components.fueled:SetDepletedFn(--[[generic_perish]]inst.Remove)
    
    return inst
end

return  Prefab("common/inventory/musicbox", fn, assets, prefabs)

 

I'm not too sure what your function fn(colour) was used for, so I just removed it.

  • Like 1
4 minutes ago, Monti18 said:

The end is placed at the wrong place so that you a piece of the function is not included, therefore it calls for inst, which is not defined outside the function.

It's always helpful for me to use identation so that you can see where an end or something like that is missing, here in your case the code in the correct form would look like that:

  Hide contents


local assets=
{ 
    Asset("ANIM", "anim/musicbox.zip"),
    Asset("ANIM", "anim/swap_musicbox.zip"), 

    Asset("ATLAS", "images/inventoryimages/musicbox.xml"),
    Asset("IMAGE", "images/inventoryimages/musicbox.tex"),
}

local prefabs = 
{
}

local function OnEquip(inst, owner) 
    --owner.AnimState:OverrideSymbol("swap_object", "swap_musicboxs", "purplestaff")
    owner.AnimState:OverrideSymbol("swap_object", "swap_musicbox", "musicbox")
    owner.AnimState:Show("ARM_carry") 
    owner.AnimState:Hide("ARM_normal") 
		
    if inst.components.fueled ~= nil then
        inst.components.fueled:StartConsuming()
    end
end

local function OnUnequip(inst, owner) 
    owner.AnimState:Hide("ARM_carry") 
    owner.AnimState:Show("ARM_normal") 
    if inst.components.fueled ~= nil then
        inst.components.fueled:StopConsuming()
    end
end

local function fn(Sim)
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("musicbox")
    anim:SetBuild("musicbox")
    anim:PlayAnimation("idle")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "musicbox"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/musicbox.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE

    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = FUELTYPE.USAGE
    inst.components.fueled:InitializeFuelLevel(TUNING.TOPHAT_PERISHTIME)
    inst.components.fueled:SetDepletedFn(--[[generic_perish]]inst.Remove)
    
    return inst
end

return  Prefab("common/inventory/musicbox", fn, assets, prefabs)

 

I'm not too sure what your function fn(colour) was used for, so I just removed it.

WAAA THANK YOU SM!! I've been agonizing over this since last night urf. I'm so glad it finally works!! ;o;;

I'm not sure either! It was likely part of the template I had been using hege

  • Like 1

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
×
  • Create New...