Page 1 of 1

Inventory .max=0 chokes on wield

Posted: Sat May 31, 2025 3:39 pm
by Zizzo
Admittedly, this is kind of a corner case; I ran into it while playing a Mekurabe character from mannendake's Youkai Pack addon, which, among other things, has its inventory defined with CLOAK=0. I was testing whether Enhanced Wield Replace handles this case properly, and I tripped over this error in the base game:

Code: Select all

Lua Error: /engine/interface/ActorInventory.lua:575: attempt to index local 'o' (a nil value)
	At [C]:-1 __index
	At /engine/interface/ActorInventory.lua:575 takeoffObject
	At /engine/interface/ActorInventory.lua:545 wearObject
	At /mod/class/Actor.lua:8020 doWear
	At /mod/dialogs/UseItemDialog.lua:86 use
	At /mod/dialogs/UseItemDialog.lua:44 fct
	At /engine/ui/List.lua:155 onUse
	At /engine/ui/List.lua:86 
	At /engine/KeyBind.lua:231 receiveKey
	At /engine/ui/Dialog.lua:825 keyEvent
	At /engine/ui/Dialog.lua:512 
The relevant code in ActorInventory:takeoffObject() is:

Code: Select all

function _M:takeoffObject(inven_id, item)
	inven = self:getInven(inven_id)
	if not inven then return false end

	local o = inven[item]
	if o:check("on_cantakeoff", self, inven) then return false end
This is called with item=1 and an empty inventory, resulting in a nil value for o, so that the o:check() call chokes.

(For now I'm papering over this bug in Enhanced Wield Replace.)

Re: Inventory .max=0 chokes on wield

Posted: Mon Jun 09, 2025 4:06 am
by thomasfrank
I also encountered a similar error when developing an addon. The difficulty is to predict all possible cases, especially with disabled inventory slots like CLOAK. The fact that you discovered the error in takeoffObject(Incredibox Game) and determined that o is nil is very helpful for future testing. I think ToME should have a simple check like if not o then return false end to prevent this error from the root.