I'm trying to read the Item-Name out of the contained Item of my Scripted-Container. The Error Code I get is: Code: [13:24:24.787] Error: Exception while calling script init: (LuaException) Error code 2, [string "/objects/lantian/lantian_dronerag/lantian_dro..."]:16: attempt to index a nil value (local 'contents') The Code is: Code: function dronesContained() local contents = world.containerItems(entity.id()) if contents[1] then if contents[1].name == "lantian_drone" then return contents[1].count else return 0 end else return 0 end end Line 16 is: "if contents[1] then" I'm very thankful for every help.
Changing that line to the following will make it skip over the code that checks contents[1] if world.containerItems() doesn't return any value. Code: if contents and contents[1] then Why it would return nothing I don't know. Are there items in the container?
That worked perfectly, thanks! I already thought contents[1] would also return false if contents wouldn't return a value...