Page 1 of 1

Food and consume_effect

Posted: Fri Jan 10, 2025 2:39 pm
by kaypy
Between system/sys_click_mouth, util/eatdrink and the consume_effect on a given object, there is a bit of a mismatch.

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

Re: Food and consume_effect

Posted: Wed Jan 15, 2025 11:41 pm
by Sophia
Makes sense. I'm not going to change "official" DSB because it has been this way for years and nobody complained, so there is probably code somewhere that actually relies on this weird behavior... because there always is. Thanks for pointing it out, though.