Jump to content

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


Recommended Posts

Hi guys,

 

I'm stumped as to how to get this working -- I'll briefly explain my problem:

 

When hosting a server with a mod character (I have created) and with another player joined as the mod character..

When I spawn a tent, straw roll, siesta hut, or fur roll (as specified in my code) it will make them crash with the error 'Attempt to index field 'sleepingbag' (a nil value)'

 

Note that I do not get this issue as the host

Here's the code that triggers the error:

(The bolded line is where the error begins)

 

local function DeepSleeper(inst)   local oldonsleep = inst.components.sleepingbag.onsleep   inst.components.sleepingbag.onsleep = function(inst, sleeper)      oldonsleep(inst, sleeper)      if sleeper.prefab == "finnthehuman" then         sleeper:DoPeriodicTask(1, function()            if inst.sleeptask ~= nil then            sleeper.components.sanity:DoDelta(2 , true)            end         end)      end   endendAddPrefabPostInit("bedroll_straw", DeepSleeper)AddPrefabPostInit("bedroll_furry", DeepSleeper) AddPrefabPostInit("tent", DeepSleeper)AddPrefabPostInit("siestahut", DeepSleeper)

Any help will be appreciated

Thank you very much

 

Link to comment
Share on other sites

@Tirimiru:

Since the mod is loaded by host and client, clients will add the postinits to their prefabs.

And clients do not have most components.

 

As such, when they run the postinit, they try to index the sleepingbag component, which is nil.

Clients don't get the sleepingbag component.

local function DeepSleeper(inst)	if not GLOBAL.TheWorld.ismastersim then		return	end	local oldonsleep = inst.components.sleepingbag.onsleep	inst.components.sleepingbag.onsleep = function(inst, sleeper)		oldonsleep(inst, sleeper)		if sleeper.prefab == "finnthehuman" then			sleeper:DoPeriodicTask(1, function()				if inst.sleeptask ~= nil then					sleeper.components.sanity:DoDelta(2 , true)				end			end)		end	endend
Link to comment
Share on other sites

@DarkXero:

 

Hi DarkXero! Thanks for your input

 

Unfortunately adding that piece of code did not help with my issue.

But good news is I found something else that did!

 

This is what I have:

local function DeepSleeper(inst)    if not inst.components.sleepingbag then        inst:AddComponent("sleepingbag")    end   local oldonsleep = inst.components.sleepingbag.onsleep   inst.components.sleepingbag.onsleep = function(inst, sleeper)      oldonsleep(inst, sleeper)      if sleeper.prefab == "finnthehuman" then         sleeper:DoPeriodicTask(1, function()            if inst.sleeptask ~= nil then            sleeper.components.sanity:DoDelta(2 , true)            else            sleeper.components.sanity:DoDelta(0, true)            end         end)      end    endend
Link to comment
Share on other sites

@Tirimiru:

Weird. It should have worked.

What you do there also works, since you add the sleepingbag component client side.

The client never uses it, but can index it just fine.

 

Are you sure what I posted doesn't work? What is the error? The same field sleepingbag is nil error?

Link to comment
Share on other sites

@DarkXero:

 

Yes, same sleepingbag nil value issue -- not sure why either.

 

Though on another note I do have another issue regarding this function

The periodic task doesn't seem to 'stop' -- what I mean by that is the first time i go in let's say a tent, it starts increasing the sanity as expected. But on the second time going in the tent, it ticks more often than normal, and the third time will be even more and so on

 

Would you know what the cause of this is?

I was trying to figure out a way to 'nullify' the periodic task when they leave the tent / sleepingbag prefab but I can't work out how

 

Please let me know if you got any ideas :)

Link to comment
Share on other sites

@Tirimiru:

I tested the code myself with the snippet I gave you and I didn't crash as client of my dedicated server.

So maybe you didn't update correctly the mod or your clients somehow didn't get it.

 

Also, to stop a periodic task:

local function DeepSleeper(inst)	if not GLOBAL.TheWorld.ismastersim then		return	end	local oldonsleep = inst.components.sleepingbag.onsleep	inst.components.sleepingbag.onsleep = function(inst, sleeper)		oldonsleep(inst, sleeper)		if sleeper.prefab == "wilson" then			inst.deeptask = sleeper:DoPeriodicTask(1, function()				if inst.sleeptask ~= nil then					sleeper.components.sanity:DoDelta(2, true)				else					if inst.deeptask ~= nil then						inst.deeptask:Cancel()						inst.deeptask = nil					end				end			end)		end	endend AddPrefabPostInit("bedroll_straw", DeepSleeper)AddPrefabPostInit("bedroll_furry", DeepSleeper) AddPrefabPostInit("tent", DeepSleeper)AddPrefabPostInit("siestahut", DeepSleeper)
  • Like 1
Link to comment
Share on other sites

@DarkXero:

 

Hmm, I'm not sure on that -- I'll have to try the Global.TheWorld.ismastersim if statement again later today without adding the sleepingbag component

 

And awesome! That code does the trick with stopping the periodic task :-)

Thank you very much for your help

Edited by Tirimiru
Link to comment
Share on other sites

@DarkXero:

 

Hmm, so Global.TheWorld.ismastersim does work after all -- client must've not copied it properly or something..

 

Sorry but I'm having another issue -- I'm unsure how to get container:WidgetSetup working on the client side

I get an error, 'attempt to index local 'widget' (a nil value)'

 

I tried to apply this solution into my modmain but it doesn't work as expected -- With the codes below I get the nil value error on host as well

Any thoughts?

local containers = require("containers")local oldwidgetsetup = containers.widgetsetup    containers.widgetsetup = function(container, prefab)    if not prefab and container.inst.prefab == "greenbackpack" then        prefab = "piggyback"    end    oldwidgetsetup(container, prefab)    end

And this is my backpack prefab

local assets ={    Asset("ANIM", "anim/greenbackpack.zip"),    Asset("ANIM", "anim/swap_greenbackpack.zip"),    Asset("ATLAS", "images/inventoryimages/greenbackpack.xml"),    Asset("IMAGE", "images/inventoryimages/greenbackpack.tex")}local function OnBlocked(owner)     owner.SoundEmitter:PlaySound("dontstarve/wilson/hit_armour") endlocal function onequip(inst, owner)     owner.AnimState:OverrideSymbol("swap_body", "swap_greenbackpack", "greenbackpack")    owner.AnimState:OverrideSymbol("swap_body", "swap_greenbackpack", "swap_body")    if inst.components.container ~= nil then        inst.components.container:Open(owner)    endendlocal function onunequip(inst, owner)     owner.AnimState:ClearOverrideSymbol("swap_body")    owner.AnimState:ClearOverrideSymbol("greenbackpack")    inst:RemoveEventCallback("blocked", OnBlocked, owner)    if inst.components.container ~= nil then    inst.components.container:Close(owner)    endendlocal function onopen(inst)	inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_open", "open")endlocal function onclose(inst)	inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_close", "open")endlocal function fn(Sim)	local inst = CreateEntity()        inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()    inst.entity:AddMiniMapEntity()    inst.entity:AddNetwork()        inst.AnimState:SetBank("backpack1")    inst.AnimState:SetBuild("swap_greenbackpack")    inst.AnimState:PlayAnimation("anim")    MakeInventoryPhysics(inst)	local minimap = inst.entity:AddMiniMapEntity()	minimap:SetIcon("greenbackpack.png")    inst.foleysound = "dontstarve/movement/foley/backpack"    if not TheWorld.ismastersim then        return inst    end    inst.entity:SetPristine()    inst:AddComponent("characterspecific")    inst:AddTag("irreplaceable")    inst:AddComponent("inspectable")    inst:AddComponent("armor")    inst.components.armor:InitCondition(TUNING.ARMORMARBLE * 1000000000000000000, TUNING.ARMORSNURTLESHELL_ABSORPTION)    inst:AddComponent("insulator")    inst.components.insulator:SetInsulation(TUNING.INSULATION_TINY)    inst:AddTag("backpack")     inst:AddComponent("container")    --inst.components.container:WidgetSetup("piggyback")    inst:AddComponent("inventoryitem")    inst.components.inventoryitem.keepondeath = true    inst.components.inventoryitem.imagename = "greenbackpack"    inst.components.inventoryitem.atlasname = "images/inventoryimages/greenbackpack.xml"    inst:AddComponent("inspectable")        inst.components.container.onopenfn = onopen    inst.components.container.onclosefn = onclose        inst:AddComponent("equippable")    inst.components.equippable.keepondeath = true	inst.components.equippable.equipslot = EQUIPSLOTS.BODY		if EQUIPSLOTS["PACK"] then		inst.components.equippable.equipslot = EQUIPSLOTS.PACK	else		inst.components.equippable.equipslot = EQUIPSLOTS.BODY	end    inst.components.equippable:SetOnEquip(onequip)    inst.components.equippable:SetOnUnequip(onunequip)    inst.components.equippable.walkspeedmult = 1.0    MakeHauntableLaunchAndDropFirstItem(inst)        return instendreturn Prefab( "common/inventory/greenbackpack", fn, assets) 

Thanks

Link to comment
Share on other sites

@DarkXero:

 

Guh, sorry to bother again.. this backpack is being poop :(

I've got a modded container component in my scripts and just got it working on the host side where when the inventory is full, items will go in the backpack (this didn't happen before and it ignored the backpack slots)

 

This is working perfectly as the host but as a client the backpack gets ignored and will say the character inventory is full

 

I can't figure out the way to make it reflecting for both host and client

Link to comment
Share on other sites

On another note when i chop down birchnut monster with my sword prefab I get an error:

 

[string "scripts/componentactions.lua"]:916: attempt to index field '?' (a nil value)

LUA ERROR strack traceback:

scripts/componentactions.lua:916 in (method) CollectionActions (Lua) <898-930>

scripts/components/playeractionpicker.lua:58 in (method) GetSceneActions (Lua) <55-80>

scripts/components/playeractionpicker.lua:176 in (method) GetLeftClickActions (Lua) <137-195>

scripts/components/playeractionpicker.lua:271 in (method) DoGetMouseActions (Lua) <240-277>

scripts/components/playercontroller.lua:1400 in (method) OnUpdate (Lua) <1286-1636>

scripts/update.lua:183 in () ? (Lua) <146-219>

Link to comment
Share on other sites

looking at componentactions.lua, the line it's failing on is

t = MOD_COMPONENT_ACTIONS[modname][type]

There's a little error catcher just above this line that tests if modname is nil. In the printout, it says "This is likely a result of your mod's calls to AddComponentAction not happening on both the server and the client."

Link to comment
Share on other sites

@Tirimiru:

I tried several times to replicate your issues on a dedicated server.

But the items go properly into my green backpack.

And I can chop purple birchnut monsters correctly.

 

Try it yourself, find a deciduous tree and run

c_find("deciduoustree"):StartMonster(true)

 

Then chop it with sword.

Link to comment
Share on other sites

On another note when i chop down birchnut monster with my sword prefab I get an error:

 

[string "scripts/componentactions.lua"]:916: attempt to index field '?' (a nil value)

LUA ERROR strack traceback:

scripts/componentactions.lua:916 in (method) CollectionActions (Lua) <898-930>

scripts/components/playeractionpicker.lua:58 in (method) GetSceneActions (Lua) <55-80>

scripts/components/playeractionpicker.lua:176 in (method) GetLeftClickActions (Lua) <137-195>

scripts/components/playeractionpicker.lua:271 in (method) DoGetMouseActions (Lua) <240-277>

scripts/components/playercontroller.lua:1400 in (method) OnUpdate (Lua) <1286-1636>

scripts/update.lua:183 in () ? (Lua) <146-219>

I'm aware of this issue, Tell me what does it say above that in the

My Documents/klei/DoNotStarveTogether/log.txt

 

Are you running any other mod's along with this one?

Link to comment
Share on other sites

@Zackreaver:

 

[00:07:00]: Error deserializing lua state for entity deciduoustree[101390] - Failed to read net var data
[00:07:07]: Error deserializing lua state for entity deciduoustree[101390] - Failed to read net var data
[00:07:07]: ERROR: Mod component actions are out of sync for mod workshop-374550642. This is likely a result of your mod's calls to AddComponentAction not happening on both the server and the client.
[00:07:07]: K: workshop-374550642 V table: 4D490130
[00:07:07]: K: 1 V: 8
[00:07:07]: K: 2 V: 2
[00:07:07]: K: 3 V: 12
[00:07:07]: K: 4 V: 47
[00:07:07]: self.modactioncomponents is
 
[00:07:07]: MOD_COMPONENT_ACTIONS is
 
[00:07:07]: [string "scripts/componentactions.lua"]:916: attempt to index field '?' (a nil value)
LUA ERROR stack traceback:
scripts/componentactions.lua:916 in (method) CollectActions (Lua) <898-930>
   self (valid:true) =
      GUID = 101390
      Transform = Transform (0A40D270)
      inlimbo = false
      actionreplica = table: 461F9260
      event_listening = table: 461F9670
      actioncomponents = table: 48A856A0
      lower_components_shadow = table: 461F8D38
      entity = Entity (31904110)
      AnimState = AnimState (0A40D4B0)
      prefab = deciduoustree
      build = normal
      Network = Network (0A40D150)
      persists = true
      MiniMapEntity = MiniMapEntity (0A40D510)
      event_listeners = table: 461F92B0
      modactioncomponents = table: 0C846398
      dragonflypriority = 1
      spawntime = 0.53333336114883
      name = Birchnut Tree
      replica = table: 461F9440
      Physics = Physics (0A40D8B0)
      components = table: 461F8E50
      SoundEmitter = SoundEmitter (0A40D4D0)
   type = SCENE
   arg = nil
   t = table: 4C263A88
   modname = workshop-374550642
   modtable = table: 4D490130
scripts/components/playeractionpicker.lua:58 in (method) GetSceneActions (Lua) <55-80>
   self =
      map = Map (4AFDBF80)
      containers = table: 0C8C17D0
      inst = 100139 - finnthehuman (valid:true)
      actionfilter = function - scripts/prefabs/player_common.lua:463
   useitem = 101390 - deciduoustree (valid:true)
   right = nil
   actions = table: 4D4928E0
scripts/components/playeractionpicker.lua:176 in (method) GetLeftClickActions (Lua) <137-195>
   self =
      map = Map (4AFDBF80)
      containers = table: 0C8C17D0
      inst = 100139 - finnthehuman (valid:true)
      actionfilter = function - scripts/prefabs/player_common.lua:463
   position = (33.80, 0.00, 50.14)
   target = 101390 - deciduoustree (valid:true)
   actions = table: 4D492408
   useitem = nil
   equipitem = 101786 - demonbloodsword (valid:true)
   ispassable = true
scripts/components/playeractionpicker.lua:271 in (method) DoGetMouseActions (Lua) <240-277>
   self =
      map = Map (4AFDBF80)
      containers = table: 0C8C17D0
      inst = 100139 - finnthehuman (valid:true)
      actionfilter = function - scripts/prefabs/player_common.lua:463
   position = (33.80, 0.00, 50.14)
   target = 101390 - deciduoustree (valid:true)
scripts/components/playercontroller.lua:1400 in (method) OnUpdate (Lua) <1286-1636>
   self =
      ondetachclassified = function - scripts/components/playercontroller.lua:89
      predictionsent = false
      predictwalking = false
      draggingonground = false
      deploy_mode = true
      highlight_guy = 101390 - deciduoustree (valid:true)
      inst = 100139 - finnthehuman (valid:true)
      remote_vector = (39.32, 4.00, 51.17)
      classified = 100781 - player_classified (valid:true)
      map = Map (4AFDBF80)
      directwalking = false
      LMBaction = Chop 101390 - deciduoustree With Inv: 101786 - demonbloodsword (valid:true)
      locomotor = table: 0BC804C8
      remote_controls = table: 0C8C4390
      ismastersim = false
      controller_target_age = 1.#INF
      mousetimeout = 10
      dragwalking = false
      handler = table: 0BC847D0
      time_direct_walking = 2.5000001303852
   dt = 0.033333335071802
   isenabled = true
   ishudblocking = nil
   controller_mode = false
   new_highlight = nil
scripts/update.lua:183 in () ? (Lua) <146-219>
   dt = 0.033333335071802
   tick = 465
   k = 100139
   v = 100139 - finnthehuman (valid:true)
   cmp = table: 0C8C47C8
 
[00:07:07]: [string "scripts/componentactions.lua"]:916: attempt to index field '?' (a nil value)
LUA ERROR stack traceback:
    scripts/componentactions.lua:916 in (method) CollectActions (Lua) <898-930>
    scripts/components/playeractionpicker.lua:58 in (method) GetSceneActions (Lua) <55-80>
    scripts/components/playeractionpicker.lua:176 in (method) GetLeftClickActions (Lua) <137-195>
    scripts/components/playeractionpicker.lua:271 in (method) DoGetMouseActions (Lua) <240-277>
    scripts/components/playercontroller.lua:1400 in (method) OnUpdate (Lua) <1286-1636>
    scripts/update.lua:183 in () ? (Lua) <146-219>
 
[00:07:07]: SCRIPT ERROR! Showing error screen
[00:07:10]: Force aborting...
 
 
Friend was the host while I was the client -- yes, some other mods other than mine were enabled
Edited by Tirimiru
Link to comment
Share on other sites

[00:07:07]: ERROR: Mod component actions are out of sync for mod workshop-374550642. This is likely a result of your mod's calls to AddComponentAction not happening on both the server and the client.
 

https://steamcommunity.com/sharedfiles/filedetails/?id=374550642

The mod mentioned in this error log is Increased Stack Size.

Consider turning that mod off and seeing if the error still happens.

 

If it still crashes, post the new log here.

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