Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Nixxon on Thu 06/11/2003 09:58:08

Title: move char when?
Post by: Nixxon on Thu 06/11/2003 09:58:08
I want character 2 to move when character 1 has reached a certain loacation x/y.

How do i go about this?
sorry for the noob-ness :P
cheers
Title: Re:move char when?
Post by: Gilbert on Thu 06/11/2003 10:11:36
If you don't mind the script to be blocked, just do:
while((character[1].x!=BLAH)&&(character[1].y!=BLARGH)) Wait(1);
MoveCharacter(2, Blargh Blargh Blargh);

Otherwise you may need to set up something in the repeatedly execute and stuff (I'm to lazy to write these stuff, unless you really need it).
Title: Re:move char when?
Post by: Nixxon on Thu 06/11/2003 10:13:18
Just thinking... would'nt it be somthing like "If" character 1 has reached as opposed to while? sorry again
basically just need the correct code for If (character is at location blah blah = 1) {
Title: Re:move char when?
Post by: Gilbert on Thu 06/11/2003 10:26:37
if would only execute once, but while would continue to execute when the expression in it is still true, so you need a while.
Title: Re:move char when?
Post by: Nixxon on Thu 06/11/2003 10:31:00
Could I paste it in the repeated execute function?
e.g
if the expression is false (character 2 stays where he is and continues to run idle view)
if the expression is true (character 2 moves towards him)

just dont know how to correctly script it
thanks again

Edit - Tried this to test, sadly did not work. displays the speech as soon as you enter the room. not when player 1 finally recheases his xy co-ords (129,133).
any ideas?

 // script for room: Repeatedly execute
GetCharacterAt(129,133);
if (GetPlayerCharacter()==1)
DisplaySpeech(EGO , "My name is ego");

 // script for room: First time player enters screen
MoveCharacterDirect (EGO, 129, 133);  

Title: Re:move char when?
Post by: SSH on Thu 06/11/2003 16:48:54
GetCharacterAt tells you which character is at that location, not whether the player has reached that location, and you would need to do something with the return value form it, anyway. GetPlayerCharacter is used for when you have more than one character than can be played with.  Just modify Gilbert's code a bit and put it in rep_ex:

// script for room: Repeatedly execute

if((character[EGO].x==129)&&(character[EGO].y==133) && (GetGlobalInt(99)==0)) {
SetGlobalInt(99, 1);
MoveCharacter(2, newx, newy);
}

Title: Re:move char when?
Post by: Gilbert on Fri 07/11/2003 02:34:40
Yes but for repeatedly execute (non blocking now), you may add some checking to it, otherwise, the same action would happen whenever the character 1 had reached that spot (worst of all, char 1 would stop at that pt, so the codes would be executed EVERY game loop from there).

And, my mistake, I wrongly used the &&, the following should work:

while((character[1].x!=BLAH)||(character[1].y!=BLARGH)) Wait(1);
MoveCharacter(2, Blargh Blargh Blargh);
Title: Re:move char when?
Post by: Nixxon on Fri 07/11/2003 05:30:58
Great, thanks for that guys :D