Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

Tirimiru

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

Recommended Posts

Tirimiru    2

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

 

Share this post


Link to post
Share on other sites
DarkXero    2,885

@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

Share this post


Link to post
Share on other sites
Tirimiru    2

@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

Share this post


Link to post
Share on other sites
DarkXero    2,885

@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?

Share this post


Link to post
Share on other sites
Tirimiru    2

@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 :)

Share this post


Link to post
Share on other sites
DarkXero    2,885

@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)

Share this post


Link to post
Share on other sites
Tirimiru    2

@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

Share this post


Link to post
Share on other sites
Tirimiru    2

@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

Share this post


Link to post
Share on other sites
DarkXero    2,885

@Tirimiru:

    if not TheWorld.ismastersim then		inst:DoTaskInTime(0.314, function() inst.replica.container:WidgetSetup("piggyback") end)        return inst    end    inst:AddComponent("container")    inst.components.container:WidgetSetup("piggyback")

Share this post


Link to post
Share on other sites
Tirimiru    2

@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

Share this post


Link to post
Share on other sites
Tirimiru    2

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>

Share this post


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

Share this post


Link to post
Share on other sites
Tirimiru    2

@StarmanUltra:

 

Hmm, would you know how to call the action for both server and client?

Seems like all my issues are to do with this -- I mean the client side calling components differently and only working properly as the host..

 

Still very new to this

Share this post


Link to post
Share on other sites
DarkXero    2,885

I can't really figure out anything with this limited knowledge of the code. Post the mod in a zip.

Share this post


Link to post
Share on other sites
DarkXero    2,885

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

Share this post


Link to post
Share on other sites
Zackreaver    140

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?

Share this post


Link to post
Share on other sites
Tirimiru    2

@DarkXero:

 

Did you play as the client? As far as I know I tested as the client while a friend was hosting the game -- also noting that we both have the mod folder

 

So as the client, backpack doesn't store properly and the tree gives me an error

Share this post


Link to post
Share on other sites
Tirimiru    2

@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

Share this post


Link to post
Share on other sites
Zackreaver    140
[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.

Share this post


Link to post
Share on other sites