SecretlyAPotato

Help with added stategraph state

Recommended Posts

Whenever I go into my custom state(which is just a slightly edited play_horn state)

My game crashes with:

Attempt to index field 'inventory' (a nil value)

the code (in my modmain)

Spoiler

local flask_state = State{
        name = "drink_flask",
        tags = {"doing", "busy"},
		onenter = function(inst)
            inst.components.locomotor:Stop()
            inst.AnimState:PlayAnimation("action_uniqueitem_pre")
            inst.AnimState:PushAnimation("horn", false)
			inst.AnimState:PushAnimation("eat", false)
            inst.AnimState:OverrideSymbol("horn01", "horn", "horn01")
            --inst.AnimState:Hide("ARM_carry")
            inst.AnimState:Show("ARM_normal")
            inst.components.inventory:ReturnActiveActionItem(inst.bufferedaction ~= nil and inst.bufferedaction.invobject or nil)
        end,

        timeline =
        {
            TimeEvent(21 * FRAMES, function(inst)
                --if inst:PerformBufferedAction() then
                    inst.SoundEmitter:PlaySound("deadcells_sfx/items/drink_flask")
			end),
			TimeEvent(70 * FRAMES, function(inst)
			inst.AnimState:SetTime(90 * FRAMES)
			--inst.AnimState:SetTime(65 * FRAMES)
			inst:DoTaskInTime(.01, function() inst.AnimState:SetTime(65 * FRAMES)end)
                --else
                    --inst.AnimState:SetTime(48 * FRAMES)
                --end
            end),
        },

        events =
        {
            EventHandler("animqueueover", function(inst)
                if inst.AnimState:AnimDone() then
                    inst.sg:GoToState("idle")
                end
            end),
        },

        onexit = function(inst)
            if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then
                inst.AnimState:Show("ARM_carry")
                inst.AnimState:Hide("ARM_normal")
            end
        end,
    },
		AddStategraphState("wilson", flask_state)
		AddStategraphState("wilson_client", flask_state)

 

 

Share this post


Link to post
Share on other sites
Monti18    407

You are adding this state to both server and client, but the client doesn't have the inventory component, it has the replica component. You will need to make a slightly different function for the wilson_client where you replace the instances of components.inventory with replica.inventory and pay attention that these functions also exist in the replica.

  • Like 1
  • Thanks 1

Share this post


Link to post
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