Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mr Jake on Thu 05/06/2003 20:55:35

Title: Cant find info on repeating functions
Post by: Mr Jake on Thu 05/06/2003 20:55:35
I want my char to make back and forward between 3 points repeatedly, I cant find the command to make this repeat.. Ive looked in:
Manual
Tut.
Forums
anywhere and everywhere else... I can find it.
sry if it is really easy, but I need to know :)
thxs
Title: Re:Cant find info on repeating functions
Post by: Scorpiorus on Thu 05/06/2003 23:05:59
It's MoveCharacterPath() that you should use. Check the manual for info.

Let's make a custom function that makes the specified character to walk between three locations:

function MovePathForwardBack(int CharID, int x1, int y1, int x2, int y2, int x3, int y3) {

 MoveCharacter(CharID, x1, y1); //goto start (1st point)
 MoveCharacterPath(CharID, x2, y2); //goto 2nd point
 MoveCharacterPath(CharID, x3, y3); //goto 3rd point
 MoveCharacterPath(CharID, x2, y2); //goto 2nd point
 MoveCharacterPath(CharID, x1, y1); //goto 1st point
}


the function gets seven parameters: character script name and by two X,Y paremeters for each of three points.

To make a repeatedly movement add the next line to the repeatedly_execute function:


function room_*() {
// room repeatedly

if (character[MAN].walking == 0) MovePathForwardBack(MAN, 100,180,  130,180,  130,150);

}

you may need to adjust the char's name and the co-ordinates of course.


-Cheers
Title: Re:Cant find info on repeating functions
Post by: Mr Jake on Fri 06/06/2003 07:26:36
error: undefiend token, 'MovePathFowardBack'
Title: Re:Cant find info on repeating functions
Post by: Gilbert on Fri 06/06/2003 07:48:10
Where did you put the definition of:
function MovePathForwardBack(...
?
Title: Re:Cant find info on repeating functions
Post by: Mr Jake on Fri 06/06/2003 07:55:11
I copied the script above to my room script (after room_*()  )
Title: Re:Cant find info on repeating functions
Post by: Gilbert on Fri 06/06/2003 08:00:24
It must placed before the function gets called, so the definition part MUST be placed before the repeatedly_execute script, you may place it on top of the script actually.

Actually I doubt why you need to add a "room_*" script inside repeatedly execute, you can do this instead:

put on TOP of the room script:
function MovePathForwardBack(int CharID, int x1, int y1, int x2, int y2, int x3, int y3) {
MoveCharacter(CharID, x1, y1); //goto start (1st point)
MoveCharacterPath(CharID, x2, y2); //goto 2nd point
MoveCharacterPath(CharID, x3, y3); //goto 3rd point
MoveCharacterPath(CharID, x2, y2); //goto 2nd point
MoveCharacterPath(CharID, x1, y1); //goto 1st point
}

The put INSIDE repeatedly execute the following line:

if (character[MAN].walking == 0) MovePathForwardBack(MAN, 100,180, 130,180, 130,150);

Title: Re:Cant find info on repeating functions
Post by: Scorpiorus on Fri 06/06/2003 09:45:32
Quotefunction room_*() {
// room repeatedly
Hotshot, it's interaction event function created by AGS editor when you add repeatedly execute in the interaction editor. The '*' sign is replaced with a letter which AGS chooses for itself.

-Cheeers
Title: Re:Cant find info on repeating functions
Post by: Mr Jake on Fri 06/06/2003 19:13:03
Same error,
Title: Re:Cant find info on repeating functions
Post by: Scorpiorus on Sat 07/06/2003 00:01:18
Can you post the room script?

Also you should decide where do you want to place the function: into the global repeatedly_execute() or into room's repeatedly. Better to room, btw. ;)

-Cheers
Title: Re:Cant find info on repeating functions
Post by: Mr Jake on Sat 07/06/2003 07:15:18
function repeatedly_execute() {
MoveCharacterPath(MIKA, 72, 146); //goto start (1st point)
MoveCharacterPath(MIKA, 227, 157); //goto 2nd point
MoveCharacterPath(MIKA, 191, 124); //goto 3rd point
}

Thats in the room script, she just stands still, unless I talk to her, then she wlaks into the corner and stands still again... (the corner isnt a waypoint)

btw: i want her to go 1,2,3,1,2,3 not 1,2,3,2,1 I might not have been clear :).
Title: Re:Cant find info on repeating functions
Post by: Scorpiorus on Sat 07/06/2003 13:36:51
Quotefunction repeatedly_execute() {
MoveCharacterPath(MIKA, 72, 146); //goto start (1st point)
MoveCharacterPath(MIKA, 227, 157); //goto 2nd point
MoveCharacterPath(MIKA, 191, 124); //goto 3rd point
}

Thats in the room script
No, you shouldn't place the function named repeatedly_execute inside the room script. It will never be called. That name is only suitable for global script.

Quotebtw: i want her to go 1,2,3,1,2,3 not 1,2,3,2,1 I might not have been clear
it's easy to adjust.


ok, let's go step-by-step then:

1. Open the whole room's script (via the {} button)

2. Add the next function on top of the script:

// room script file
function MovePathForwardBack(int CharID, int x1, int y1, int x2, int y2, int x3, int y3) {

MoveCharacter(CharID, x1, y1); //goto start (1st point)
MoveCharacterPath(CharID, x2, y2); //goto 2nd point
MoveCharacterPath(CharID, x3, y3); //goto 3rd point

}


3. Now goto the interaction editor.
4. Choose repeatedly execute event.
5. From the list select the Run script command.
6. Push Edit script... button and add the following line:


// script for room: Repeatedly execute
if (character[MIKA].walking == 0) MovePathForwardBack(MIKA, 72,146, 227,157, 191,124);


that's all.

if you open the whole room script again you will see there is a function, something like:

function room_*() {
// script for room: Repeatedly execute

if (character[MIKA].walking == 0) MovePathForwardBack(MIKA, 72,146, 227,157, 191,124);

}

'*' - you see a character instead
It is that function that is room's repeatedly!

how it goes?

-Cheers
Title: Re:Cant find info on repeating functions
Post by: Mr Jake on Sat 07/06/2003 20:20:21
thxs and OMG Im dum :)
didnt notice the repeated execute in the interaction editor  :o

kay.. since I dont really understand whats going on in this script...

I want now to make char :MIKA stop at each point and wait, displayingspeech in the background (.......) and then speech in the background of the person shes talking too... (again, ........).
thxs for the help every1
Title: Re:Cant find info on repeating functions
Post by: Scorpiorus on Mon 09/06/2003 20:34:17
It's more complicated since AGS hasn't functions like MoveCharacterPath() but for speeching and waiting. We have discussed this prbolem with juncmodule (here (http://www.agsforums.com/yabb/index.php?board=2;action=display;threadid=1887;prev_next=next))

Ok the next code is probably what you neeed:

//room script

//at the top of the room script
int NeedChecking = 0; //is set to 1 after calling StartMikaActions();
int ActionNumber = 0; //stores the next action to proceed.
int PauseCounter = 0; //is used for 'pause' action.

function StartMikaActions() {
NeedChecking = 1; //enables checking;
ActionNumber = 1; //sets the first action to proceed;
}

...
...
...

function room_*() {
// script for room: Repeatedly execute

if (NeedChecking == 1) { //if StartMikaActions() has been called...

  //if paused then decrease pause.
  if (PauseCounter>0) PauseCounter--;

  //if character is doing nothing then proceed the next action...
  if ((character[MIKA].walking == 0) &&
  (character[MIKA].animating == 0) &&
  (PauseCounter <= 0)) {

  if (ActionNumber == 1) {
     MoveCharacter(MIKA, 72,146);
     ActionNumber = 2;
  }
  else if (ActionNumber == 2) {
     DisplaySpeechBackground(MIKA, "blah blah ..... 1");
     PauseCounter = 100;
     ActionNumber = 3;
  }
  else if (ActionNumber == 3) {
     MoveCharacter(MIKA, 227,157);
     ActionNumber = 4;
  }
  else if (ActionNumber == 4) {
     DisplaySpeechBackground(MIKA, "blah blah ..... 2");
     PauseCounter = 100;
     ActionNumber = 5;
  }
  else if (ActionNumber == 5) {
     MoveCharacter(MIKA, 191,124);
     ActionNumber = 6;
  }
  else if (ActionNumber == 6) {
     DisplaySpeechBackground(MIKA, "blah blah ..... 3");
     PauseCounter = 100;
     ActionNumber = 1;
  }
  }


} //end of needchecking block



} //end of room's repeatedly




to start the actions call the next function:
for example from player enters screen (after faid-in)

function room_*() {
// player enters screen (after faid-in)

 StartMikaActions(); //<----- this way

}


how it turns out?

-Cheers