SecretlyAPotato Posted September 7, 2021 Share Posted September 7, 2021 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) Link to comment https://forums.kleientertainment.com/forums/topic/133385-help-with-added-stategraph-state/ Share on other sites More sharing options...
Monti18 Posted September 8, 2021 Share Posted September 8, 2021 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. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/133385-help-with-added-stategraph-state/#findComment-1492233 Share on other sites More sharing options...
SecretlyAPotato Posted September 9, 2021 Author Share Posted September 9, 2021 Oh thank you once again! I haven't tried it yet but it sounds simple enough, so I don't think I'll have an issue Link to comment https://forums.kleientertainment.com/forums/topic/133385-help-with-added-stategraph-state/#findComment-1492728 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now