Tirimiru Posted August 2, 2015 Share Posted August 2, 2015 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 hostHere'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 appreciatedThank you very much Link to comment Share on other sites More sharing options...
Tirimiru Posted August 3, 2015 Author Share Posted August 3, 2015 Sorry, didn't seem to bold the line. Line 2 is where the error starts Link to comment Share on other sites More sharing options...
DarkXero Posted August 3, 2015 Share Posted August 3, 2015 @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 More sharing options...
Tirimiru Posted August 3, 2015 Author Share Posted August 3, 2015 @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 More sharing options...
DarkXero Posted August 3, 2015 Share Posted August 3, 2015 @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 More sharing options...
Tirimiru Posted August 4, 2015 Author Share Posted August 4, 2015 @DarkXero: Yes, same sleepingbag nil value issue -- not sure why either. Though on another note I do have another issue regarding this functionThe 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 More sharing options...
Maris Posted August 4, 2015 Share Posted August 4, 2015 Crash screen shows filename and exact line number. Link to comment Share on other sites More sharing options...
DarkXero Posted August 4, 2015 Share Posted August 4, 2015 @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) 1 Link to comment Share on other sites More sharing options...
Tirimiru Posted August 5, 2015 Author Share Posted August 5, 2015 (edited) @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 August 5, 2015 by Tirimiru Link to comment Share on other sites More sharing options...
Tirimiru Posted August 5, 2015 Author Share Posted August 5, 2015 @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 sideI 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 wellAny 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) endAnd this is my backpack prefablocal 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 More sharing options...
DarkXero Posted August 5, 2015 Share Posted August 5, 2015 @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") Link to comment Share on other sites More sharing options...
Tirimiru Posted August 6, 2015 Author Share Posted August 6, 2015 @DarkXero: Yeeeeeeesss! What a beast DarkXero -- solved it so easilyThanks a lot for your help! I'll learn a lot from you Link to comment Share on other sites More sharing options...
Tirimiru Posted August 7, 2015 Author Share Posted August 7, 2015 @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 More sharing options...
Tirimiru Posted August 7, 2015 Author Share Posted August 7, 2015 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 More sharing options...
StarmanUltra Posted August 8, 2015 Share Posted August 8, 2015 looking at componentactions.lua, the line it's failing on ist = 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 More sharing options...
Tirimiru Posted August 8, 2015 Author Share Posted August 8, 2015 @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 Link to comment Share on other sites More sharing options...
StarmanUltra Posted August 8, 2015 Share Posted August 8, 2015 Haven't the foggiest... I'm pretty new too, which means I've been running into a lot of "attempt to index nil" as well. Link to comment Share on other sites More sharing options...
DarkXero Posted August 8, 2015 Share Posted August 8, 2015 I can't really figure out anything with this limited knowledge of the code. Post the mod in a zip. Link to comment Share on other sites More sharing options...
Tirimiru Posted August 9, 2015 Author Share Posted August 9, 2015 @StarmanUltra: Damn, I know how that feels.. XD Link to comment Share on other sites More sharing options...
Tirimiru Posted August 9, 2015 Author Share Posted August 9, 2015 @DarkXero: I've uploaded the mod, you can find it in my content Link to comment Share on other sites More sharing options...
DarkXero Posted August 11, 2015 Share Posted August 11, 2015 @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 runc_find("deciduoustree"):StartMonster(true) Then chop it with sword. Link to comment Share on other sites More sharing options...
Zackreaver Posted August 11, 2015 Share Posted August 11, 2015 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 theMy Documents/klei/DoNotStarveTogether/log.txt Are you running any other mod's along with this one? Link to comment Share on other sites More sharing options...
Tirimiru Posted August 11, 2015 Author Share Posted August 11, 2015 @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 Link to comment Share on other sites More sharing options...
Tirimiru Posted August 11, 2015 Author Share Posted August 11, 2015 (edited) @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: 4D490130scripts/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: 4D4928E0scripts/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 = truescripts/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 = nilscripts/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 August 11, 2015 by Tirimiru Link to comment Share on other sites More sharing options...
Zackreaver Posted August 11, 2015 Share Posted August 11, 2015 [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=374550642The 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 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