Hey guys,
I discovered tonight that the party's "onMove" hook seems only to be triggered after a certain delay between inputs (i.e., the hook is not called if the party continues in the same direction/quickly changes direction without interruption). Is there any more reliable known way to detect a change in the party's position via hooks, in other words to avoid the above situations?
[Solved] Issue with party's onMove hook
[Solved] Issue with party's onMove hook
Last edited by Jgwman on Sun Jun 12, 2016 8:14 pm, edited 1 time in total.
Re: Issue with party's onMove hook
Can you post an a script example?
** Here is a quick hook script that I tried this with, but I'm not seeing the problem. [yet]
**OnMove does get called regardless of whether the move succeeds, and so bumping into a wall for instance, would see more calls to the hook, than tiles actually moved.
Aside from hooks, you would have to aggressively poll the x/y/e to know [afaik], and that would require a timer; (or an impractical number of floor _triggers)... as well as being less reliable I think.
***Curiously, I find that while the tiles-moved registers a change in elevation, it does not register the first move after the change. So stepping to a ladder, up the ladder, and off of the ladder ~counts as two tiles moved.
** Here is a quick hook script that I tried this with, but I'm not seeing the problem. [yet]
Code: Select all
party.party:addConnector("onMove", self.go.id, "report")
move = 0
function report(self, dir)
print("hook called:",move," dir:", dir, "tiles moved:",GameMode.getStatistic("tiles_moved"))
move = move + 1
endAside from hooks, you would have to aggressively poll the x/y/e to know [afaik], and that would require a timer; (or an impractical number of floor _triggers)... as well as being less reliable I think.
***Curiously, I find that while the tiles-moved registers a change in elevation, it does not register the first move after the change. So stepping to a ladder, up the ladder, and off of the ladder ~counts as two tiles moved.
Re: Issue with party's onMove hook
PC is off now, but I can summarize what I was doing a bit better (and post code tomorrow if it can't be solved).
Essentially, I have a custom monster casting a projectile (its AI is for testing purposes set to cast this projectile each onThink loop during which the party is on a certain axis, i.e. in front of the monster). Each cast, an onMove hook is registered with the party via Jkos's framework. The hook function should set a bool to true which is checked in the onThink loop that if true, spawns a force field to deflect the projectile toward where the party moved to (the bool is then reset to false and the onMove hook removed).
This works entirely as intended, other than a situation in which the party quickly moves in front and then back (or keeps going across). In this scenario, the projectile is spawned (when party enters line of sight), but no force field spawned (should spawn on the move out of line of sight - and does, if I delay the second movement slightly). Instead, it spawns on the next movement (debugging hudPrints confirm that the hook was added but not triggered, and then on the next move confirms the trigger). I'll definitely check my onThink loop again to make sure nothing weird is happening there, but as far as I can tell that's not the issue (though it does seem more likely).
Essentially, I have a custom monster casting a projectile (its AI is for testing purposes set to cast this projectile each onThink loop during which the party is on a certain axis, i.e. in front of the monster). Each cast, an onMove hook is registered with the party via Jkos's framework. The hook function should set a bool to true which is checked in the onThink loop that if true, spawns a force field to deflect the projectile toward where the party moved to (the bool is then reset to false and the onMove hook removed).
This works entirely as intended, other than a situation in which the party quickly moves in front and then back (or keeps going across). In this scenario, the projectile is spawned (when party enters line of sight), but no force field spawned (should spawn on the move out of line of sight - and does, if I delay the second movement slightly). Instead, it spawns on the next movement (debugging hudPrints confirm that the hook was added but not triggered, and then on the next move confirms the trigger). I'll definitely check my onThink loop again to make sure nothing weird is happening there, but as far as I can tell that's not the issue (though it does seem more likely).
Re: Issue with party's onMove hook
Like Isaac, I cannot reproduce your problem at all. onMove gets called on every move, even if I move once every frame, or move multiple times in one frame.
Isaac, climbing a ladder is not a move. You can detect whether the party is on a ladder by checking party.gravity:isEnabled(), which will return false if the party is on a ladder and true otherwise. By checking this every frame, you can detect when the party first climbs a ladder, although you'll be a frame too late to stop them from climbing the ladder.
Isaac, climbing a ladder is not a move. You can detect whether the party is on a ladder by checking party.gravity:isEnabled(), which will return false if the party is on a ladder and true otherwise. By checking this every frame, you can detect when the party first climbs a ladder, although you'll be a frame too late to stop them from climbing the ladder.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Issue with party's onMove hook
Must be some other mistake of mine I missed then, my bad. Thanks for checking.
Re: Issue with party's onMove hook
Are you removing the previous hooks when you add new ones?Jgwman wrote:Each cast, an onMove hook is registered with the party via Jkos's framework.
@minmay : The engine does seem to [technically] count climbing as a tile moved though.
(The statistic tiles_moved will increment for climbing a ladder, but then does not increment again for the subsequent move to another tile (away from the ladder).
(...or for climbing the ladder again. It must be some sort of engine quirk.)
Re: Issue with party's onMove hook
I was indeed removing the hooks. The issue was a simple one - I had the projectile casted, and the hook registered, during onAnimationEvent for the spell, which was not early enough registration of the hook, so I just moved it to onBeginAction. My fault 