Jump to content

Crash: attempt to index field 'inventoryitem'


Recommended Posts

Hi,

I have a custom mod that has character and a custom container. I've been playing with my son for a few hours with no problem until he crashed (as a client).

 

Log:

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

Log is attached.

 

The lua file for this item:

local assets={	Asset("ANIM", "anim/bkgoblinsack.zip"),	Asset("IMAGE", "images/inventoryimages/bkgoblinsack.tex"),		Asset("ATLAS", "images/inventoryimages/bkgoblinsack.xml")}local function OnDropped(inst)    inst.Light:Enable(true)endlocal function OnPickup(inst)    inst.Light:Enable(false)endlocal function fn()	local inst = CreateEntity()		inst.entity:AddTransform()	inst.entity:AddAnimState()	inst.entity:AddLight()	inst.entity:AddNetwork()		MakeInventoryPhysics(inst)		inst.AnimState:SetBank("bkgoblinsack")	inst.AnimState:SetBuild("bkgoblinsack")	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("inspectable")	inst:AddComponent("inventoryitem")	inst.components.inventoryitem.imagename = "bkgoblinsack"	inst.components.inventoryitem.atlasname = "images/inventoryimages/bkgoblinsack.xml"	inst.components.inventoryitem:SetOnDroppedFn(OnDropped)    inst.components.inventoryitem:SetOnPickupFn(OnPickup)	inst:AddComponent("container")    inst.components.container:WidgetSetup("treasurechest")		inst:AddComponent("sanityaura")    inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY		MakeHauntableLaunchAndDropFirstItem(inst)    	return instendSTRINGS.NAMES.BKGOBLINSACK = "BK Goblin Sack"STRINGS.CHARACTERS.GENERIC.DESCRIBE.BKGOBLINSACK = "Test"return Prefab( "common/inventory/bkgoblinsack", fn, assets) 

Help?

 

Thanks.

log2.txt

Link to comment
Share on other sites

Move:

inst:AddComponent("inventoryitem")inst.components.inventoryitem.imagename = "bkgoblinsack"inst.components.inventoryitem.atlasname = "images/inventoryimages/bkgoblinsack.xml"

before:

if not TheWorld.ismastersim then     return instend

part.

 

This crash occured becouse your entity was missing  a "inventoryitem" component on client's side. If something needs to be run both on client and server, move it before "if not TheWorld.ismastersim (...)".

 

I think you should move

inst:AddComponent("inspectable")

too, otherwise you won't be able to examine this item as client.

Link to comment
Share on other sites

@SenL, That line is referencing the inventoryitem replica. So something is preventing the inventoryitem component from replicating for your item, I think... Which is really bizarre. That should not happen...

 

Moving it above TheWorld.ismastersim is not the right thing to do, though. The inventoryitem component should only exist on the server, so it should definitely be below. What's supposed to happen is that clients will get a replica inventoryitem instead of a component, but something must be messing with that.

 

As a side note, you should probably be putting the STRINGS stuff into the modmain (you'll have to use GLOBAL.STRINGS, of course).

 

Sorry I couldn't be more helpful with the source of the problem, though :(

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