The consume_effect is called with the id of the object being consumed. But because food has an animation and thus a delay, the object is no longer valid by the time its consume_effect is called.
I have a tweaked version that uses the stop_con return to prevent the food item being do_convert-ed, then manually handles the do_convert after the delay and consume_effect.
Code: Select all
function eatdrink(self, id, who)
local delay = false
if (self.foodval) then
inventory_info.mouth.icon = gfx.mouth_chewing
dsb_update_inventory_info()
dsb_hide_mouse()
dsb_delay_func(1, function() dsb_lock_game() end)
dsb_delay_func(4, function ()
dsb_show_mouse()
dsb_sound(base_eat_sound)
inventory_info.mouth.icon = base_mouth_icon
dsb_update_inventory_info()
dsb_set_food(who, dsb_get_food(who) + self.foodval)
if (self.waterval) then
dsb_set_water(who, dsb_get_water(who) + self.waterval)
end
if (self.consume_effect) then
self:consume_effect(id, who)
end
-- manually apply conversion
local arch = dsb_find_arch(id)
do_convert(arch, id, "consume")
dsb_unlock_game()
end)
delay = true
elseif (self.waterval) then
dsb_set_water(who, dsb_get_water(who) + self.waterval)
end
if (not delay) then
if (self.consume_effect) then
self:consume_effect(id, who)
end
dsb_sound(base_eat_sound)
end
if delay then
-- dont do_convert until after delay
return true
end
end