Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tamanegi on Tue 14/12/2010 20:10:20

Title: SOLVED: "walks onto region" fails with scripted movement
Post by: Tamanegi on Tue 14/12/2010 20:10:20
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:

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
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?
Title: Re: "walks onto region" fails with scripted movement
Post by: Mati256 on Tue 14/12/2010 20:24:49
You could use IsCollidingWithObject under the room_RepExec function.
Title: Re: "walks onto region" fails with scripted movement
Post by: monkey0506 on Tue 14/12/2010 20:27:22
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:

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..
Title: Re: "walks onto region" fails with scripted movement
Post by: Tamanegi on Tue 14/12/2010 20:39:59
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  ::)
Title: Re: "walks onto region" fails with scripted movement
Post by: Khris on Wed 15/12/2010 04:56:48
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.
Title: Re: SOLVED: "walks onto region" fails with scripted movement
Post by: Calin Leafshade on Wed 15/12/2010 07:28:41
also remember the Game.DoOnlyOnce() function.
Title: Re: SOLVED: "walks onto region" fails with scripted movement
Post by: Tamanegi on Wed 15/12/2010 09:30:07
@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
if (Game.DoOnceOnly("blabla")==false) {
 // do stuff
}

Well, it works now, no need to change it  ;D  But it taught me a lot.