Page 1 of 1

Possible Item Activation Fix

Posted: Fri Mar 11, 2011 4:20 am
by edge2054
Started digging around tonight with the help of Marcotte on IRC and found this in module Object.lua line 87

Code: Select all

	if typ == "use" then
		who:useEnergy(game.energy_to_act * (inven.use_speed or 1))
		if self.use_sound then game:playSoundNear(who, self.use_sound) end
		return self:useObject(who, inven, item)
	end
Marcotte and Grey suggested swapping the useObject and the useEnergy around.

Code: Select all

	if typ == "use" then
		self:useObject(who, inven, item)
		if self.use_sound then game:playSoundNear(who, self.use_sound) end
		return who:useEnergy(game.energy_to_act * (inven.use_speed or 1))
	end
Initial testing of this fixes the item activation bug with targeted items (and I tested a non-targeted item to make sure they still worked alright). Maybe I'm missing something crucial, I don't know. But it looks like a potential fix.

Re: Possible Item Activation Fix

Posted: Fri Mar 11, 2011 4:24 am
by Marcotte
Just a quick comment: your code changes the return value of the function. Here would be a fix for that:

Code: Select all

   if typ == "use" then
      local ret = self:useObject(who, inven, item)
      if ret then
         if self.use_sound then game:playSoundNear(who, self.use_sound) end
         who:useEnergy(game.energy_to_act * (inven.use_speed or 1))
      end
      return ret
   end