Conker446 Posted January 5, 2015 Share Posted January 5, 2015 (edited) I updated a new item which have the function of original chest. The difference of this item compared to original is that this item can be pickable. And it's owner can open it at one's inventory by clicking the right button. As a host, everything was fine to me. But, whenever my friend try to open this item as a guest, It always shows WARNING message showing that attempt to index local 'widget' (a nil value) Because this item's code is not complicate, I want to get advice from you guys by showing this. Please let me show you. local assets={ Asset("ANIM", "anim/buckyball.zip"), Asset("ATLAS", "images/inventoryimages/buckyball.xml"), Asset("IMAGE", "images/inventoryimages/buckyball.tex")} local function OnDropped(inst) inst.Light:Enable(true)end local function OnPickup(inst) inst.Light:Enable(false)end local function onopen(inst) inst.SoundEmitter:PlaySound("dontstarve/common/butterfly_trap") end local function onclose(inst) inst.SoundEmitter:PlaySound("dontstarve/common/butterfly_trap")end local function fn()local inst = CreateEntity() inst.entity:AddTransform()inst.entity:AddAnimState()inst.entity:AddSoundEmitter() inst.entity:AddLight() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("bulb") inst.AnimState:SetBuild("buckyball") inst.AnimState:PlayAnimation("idle") inst.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" ) local light = inst.entity:AddLight() light:SetFalloff(0.7) light:SetIntensity(.5) light:SetRadius(1.0) light:SetColour(237/255, 237/255, 209/255) light:Enable(true) if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("tradable") inst:AddComponent("inspectable") inst:AddComponent("fuel") inst.components.fuel.fuelvalue = TUNING.TINY_FUEL inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/buckyball.xml" inst.components.inventoryitem:SetOnDroppedFn(OnDropped) inst.components.inventoryitem:SetOnPickupFn(OnPickup) inst:AddComponent("container") inst.components.container:WidgetSetup("treasurechest") inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose MakeHauntableLaunchAndDropFirstItem(inst) return instend return Prefab( "common/inventory/buckyball", fn, assets ) Edited January 5, 2015 by Conker446 Link to comment Share on other sites More sharing options...
Conker446 Posted January 5, 2015 Author Share Posted January 5, 2015 (edited) Edited January 5, 2015 by Conker446 Link to comment Share on other sites More sharing options...
rezecib Posted January 5, 2015 Share Posted January 5, 2015 (edited) inst.components.container:WidgetSetup("treasurechest")Currently the container widget functions refer to the prefab name of the object they're making a container widget for. There's a workaround I posted somewhere, I'll see if I can find it... But in the future, make sure you also include the file and line number that the error is coming from. That will help diagnose the problem. Edit: Here it is:local containers = GLOBAL.require("containers")local oldwidgetsetup = containers.widgetsetupcontainers.widgetsetup = function(container, prefab) if not prefab and container.inst.prefab == "pak" then prefab = "backpack" end oldwidgetsetup(container, prefab)end Edited January 5, 2015 by rezecib Link to comment Share on other sites More sharing options...
Conker446 Posted January 5, 2015 Author Share Posted January 5, 2015 Currently the container widget functions refer to the prefab name of the object they're making a container widget for. There's a workaround I posted somewhere, I'll see if I can find it... But in the future, make sure you also include the file and line number that the error is coming from. That will help diagnose the problem. Edit: Here it is:local containers = GLOBAL.require("containers")local oldwidgetsetup = containers.widgetsetupcontainers.widgetsetup = function(container, prefab) if not prefab and container.inst.prefab == "pak" then prefab = "backpack" end oldwidgetsetup(container, prefab)end Oh, thank you for your helping me. But... If you don't mind, can you show me more specific way to apply this code? I tried what you told me to do and it has no response without any message in DST. I know that the code you gave me have to be revised, but I failed several times.. Link to comment Share on other sites More sharing options...
Conker446 Posted January 6, 2015 Author Share Posted January 6, 2015 Currently the container widget functions refer to the prefab name of the object they're making a container widget for. There's a workaround I posted somewhere, I'll see if I can find it... But in the future, make sure you also include the file and line number that the error is coming from. That will help diagnose the problem. Edit: Here it is:local containers = GLOBAL.require("containers")local oldwidgetsetup = containers.widgetsetupcontainers.widgetsetup = function(container, prefab) if not prefab and container.inst.prefab == "pak" then prefab = "backpack" end oldwidgetsetup(container, prefab)end Thank you recezib! I solved that problem. I thought that "pak" is a code that must be added XD. Anyway, really sorry for bothering you 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