onEquipItem crash
Posted: Fri Mar 15, 2013 2:17 am
I'm having trouble creating a particular effect upon equipping an item. If I use the onEquipItem hook (as implemented/commented-out below), the game crashes without an error message upon equipping it in-hand. I have tried to create a work-around with a script entity (whose code I found and borrowed from the site... I don't remember who it's from, but will make sure they are properly credited if I do end up using it). The script entity work-around functions all of the time in the Dungeon Editor, but is prone to causing crashes (with an error log, below) upon holding the item in-hand and clicking a healing crystal when run as a Custom Dungeon.
My code/error messages are as follows:
onEquipItem hook [ideally I could find what's wrong with this and just use it]
script_entity_7.itemCheck() [the work-around]
The error read-out
This error message does encourage me to submit the error log to feedback@almosthumangames.com, which I've done, but I thought I might get a faster response asking on the forum. As usual, any and all help appreciated. Thank you.
My code/error messages are as follows:
onEquipItem hook [ideally I could find what's wrong with this and just use it]
Code: Select all
onEquipItem = function()
script_entity_7.itemCheck()
return true
end
--onEquipItem = function(champion, slot)
-- for champ = 1,4 do
-- for slot = 7,8 do
-- party:getChampion(ch):setCondition("poison", 30)
-- return true
-- end
-- end
--end
--this commented-out onEquipItem section makes the Dungeon Editor crash when the item is in-hand (with no subsequent error message)
Code: Select all
function itemCheck()
-- supposing the item causing the crash is actually named "item"
for champ = 1,4 do
for slot = 7,8 do
x = party:getChampion(champ):getItem(slot)
if x ~= nil then
if x.name == "item" then
party:getChampion(champ):setCondition("poison", 30)
end
end
end
end
end
Code: Select all
script_entity_7: cannot serialize table 'x' with metatable stack traceback:
[C]: in function 'error'
[string "ScriptEntity.lua"]: in function 'saveValue'
[string "ScriptEntity.lua"]: in function 'saveState'
[string "GameMode.lua"]: in function 'saveGame'
[string "GameMode.lua"]: in function 'autoSave'
[string "Crystal.lua"]: in function 'onClick'
[string "GameMode.lua"]: in function 'mousePressed'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk