Page 1 of 1

[BUG] party:onMove hook

Posted: Sat Oct 13, 2012 11:40 pm
by Leki
I spend a lot of time with polishing events based on "party:onMove". Results were tragic, so I did some console logs to track the problem. Now I have a simple code:

Code: Select all

cloneObject{
	name = "party",
	baseObject = "party",
	onMove = function(self, dir)
				print("party location: ", "L=", self.level, "X=", self.x, "Y=", self.y, "MoveDir=", dir)
			 end,
	onTurn = function(self, dir)
		  print("party location: ", "L=", self.level, "X=", self.x, "Y=", self.y, "TirnDir=", dir)
	end,	
}
Testcase:
Start with
party.x = 0
party.x = 0
dir = 1 (east)

Try to move 4 steps in dir = 1 (loking east) and after that do one step west (keep dir=1 - looking east).
Console shows X = 5 but but your real location is party.x = 3
turning updates party.x and party.y into correct numbers
hitting obstacle updates party.x and party.y into correct numbers as well

Question:
What is wrong in my code
or
How to get party position, when movement is finished without spawning timer (0.5 sec is minimum) and asking Lua script for party pos etc...

Re: [BUG] party:onMove hook

Posted: Sun Oct 14, 2012 8:52 pm
by petri
The onMove hook is called before movement (otherwise the hook couldn't cancel the action), so self.x,self.y are the coordinates of the the source square. To get the target square you can do:

local dx,dy = getForward(dir)
local x,y = self.x + dx, self.y + dy

Hope this helps!

Re: [BUG] party:onMove hook

Posted: Tue Oct 16, 2012 1:59 pm
by Leki
petri wrote:The onMove hook is called before movement (otherwise the hook couldn't cancel the action), so self.x,self.y are the coordinates of the the source square. To get the target square you can do:

local dx,dy = getForward(dir)
local x,y = self.x + dx, self.y + dy

Hope this helps!

getForward(dir) - thats it! Thanks a lot petri!

Re: [BUG] party:onMove hook

Posted: Tue Oct 16, 2012 2:36 pm
by Xanathar
On topic with "onMove" weirdness...
I'm trying to write a generic "party:teleport" functionality.

I'm creating a teleport object on the fly and thought about using an hook like:

Code: Select all

   
    onMove = function(self, dir)
       if temporary_teleporter ~= nil then
			hudPrint("destroying teleport")
			-- temporary_teleporter.deactivate()
                        -- temporary_teleporter.destroy()
			temporary_teleporter = nil
	   end
   end,
Basically both the deactivate and the destroy calls will crash the editor (and likely the game too). Is this a bug or are there by-design limitations on what can be done in onMove hooks ?

Re: [BUG] party:onMove hook

Posted: Fri Oct 19, 2012 3:26 pm
by Grimwold
Xanathar wrote:On topic with "onMove" weirdness...
I'm trying to write a generic "party:teleport" functionality.

I'm creating a teleport object on the fly and thought about using an hook like:

Code: Select all

   
    onMove = function(self, dir)
       if temporary_teleporter ~= nil then
			hudPrint("destroying teleport")
			-- temporary_teleporter.deactivate()
                        -- temporary_teleporter.destroy()
			temporary_teleporter = nil
	   end
   end,
Basically both the deactivate and the destroy calls will crash the editor (and likely the game too). Is this a bug or are there by-design limitations on what can be done in onMove hooks ?
Don't know if you've already figured this out, but you need colons instead of dots

Code: Select all

temporary_teleporter:deactivate()
temporary_teleporter:destroy()

Re: [BUG] party:onMove hook

Posted: Fri Oct 19, 2012 6:48 pm
by Xanathar
Good spot!
My typo, very likely that was the cause - will retry with colons when I can.