Possible Item Activation Fix

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
edge2054
Retired Ninja
Posts: 3756
Joined: Fri May 28, 2010 4:38 pm

Possible Item Activation Fix

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

Marcotte
Wyrmic
Posts: 203
Joined: Sat Jan 26, 2008 1:12 am

Re: Possible Item Activation Fix

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

Post Reply