Inventory .max=0 chokes on wield

Make all T-Engine/ToME 4 bug reports here

Moderator: Moderator

Post Reply
Message
Author
Zizzo
Sher'Tul Godslayer
Posts: 2517
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Inventory .max=0 chokes on wield

#1 Post 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.)
"Blessed are the yeeks, for they shall inherit Arda..."

thomasfrank
Posts: 3
Joined: Mon Jun 02, 2025 10:46 am

Re: Inventory .max=0 chokes on wield

#2 Post 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.

Post Reply