[BUG] party:onMove hook

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

[BUG] party:onMove hook

Post 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...
I'm the Gate I'm the Key.
Dawn of Lore
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [BUG] party:onMove hook

Post 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!
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

Re: [BUG] party:onMove hook

Post 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!
I'm the Gate I'm the Key.
Dawn of Lore
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: [BUG] party:onMove hook

Post 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 ?
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: [BUG] party:onMove hook

Post 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()
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: [BUG] party:onMove hook

Post by Xanathar »

Good spot!
My typo, very likely that was the cause - will retry with colons when I can.
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
Post Reply