SOLVED: "walks onto region" fails with scripted movement

Started by Tamanegi, Tue 14/12/2010 20:10:20

Previous topic - Next topic

Tamanegi

I want the player character to stop moving and do something when he walks onto a region for the first time. I put it like this:

Code: ags
function region1_WalksOnto()
{
  if (alreadydone==false) {
    player.StopMoving();
    // do stuff
    alreadydone=true;
  }
}


It works, but only when moving with the move cursor. When I interact with an object and the interaction script tells the character to move somewhere, he doesn't stop at the region and doesn't do what he should do. I suppose that's because the region isn't checked while another script is running.

I tried putting
Code: ags
function room_RepExec()
{
  if ((alreadydone==false)&&(Region.GetAtRoomXY(player.x, player.y) == region[1]))
    region1_WalksOnto();
}


as "repeatedly execute"-action, but I guess since the movement is "eBlock", the "repeatedly execute" script isn't executed at that time.

Is there a good workaround, or am I simply missing something?
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Mati256

You could use IsCollidingWithObject under the room_RepExec function.
My Blog! (En Español)

monkey0506

If the movement is blocking then presumably that would also prevent the region functions..but you can call your WalksOnto function from repeatedly_execute_always since it itself is non-blocking:

Code: ags
function repeatedly_execute_always()
{
  if ((alreadydone==false)&&(Region.GetAtRoomXY(player.x, player.y) == region[1]))
    region1_WalksOnto();
}


Note that rep_ex_always doesn't get linked in the events pane, it just gets called anyway.

Edit: room_RepExec is never called during a blocking interaction, so that still wouldn't affect anything Mati..

Tamanegi

Thank you, putting it into repeatedly_execute_always did the trick. I wonder why it isn't a visible trigger in the events window...

I had to do things a little different though because repeatedly_execute_always doesn't allow blocking actions such as Character.Say(), so I just put Character.StopMovement() there and used "standing on region" as the trigger.

All interactions that trigger movement check upon standstill if the player has reached his destination before continuing to prevent "remote control" effects  ::)
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Khris

Quote from: Tamanegi on Tue 14/12/2010 20:39:59
All interactions that trigger movement check upon standstill if the player has reached his destination before continuing to prevent "remote control" effects  ::)

Have a look at my module:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36383.msg477380#msg477380

It provides a relatively convenient way to do what you describe.

Calin Leafshade


Tamanegi

@Khris: I don't really know modules at this point, and I only need to do this in one place anyway, but I will remember that  ;)

@Calin: Good to know, but in this case it would be impractical because I need to remember if the event has happened for other things to take place. Although I guess I could just use
Code: ags
if (Game.DoOnceOnly("blabla")==false) {
  // do stuff
}

Well, it works now, no need to change it  ;D  But it taught me a lot.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

SMF spam blocked by CleanTalk