Cant find info on repeating functions

Started by Mr Jake, Thu 05/06/2003 20:55:35

Previous topic - Next topic

Mr Jake

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

Scorpiorus

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

Mr Jake

error: undefiend token, 'MovePathFowardBack'

Gilbert

Where did you put the definition of:
function MovePathForwardBack(...
?

Mr Jake

I copied the script above to my room script (after room_*()  )

Gilbert

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);


Scorpiorus

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

Mr Jake


Scorpiorus

#8
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

Mr Jake

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 :).

Scorpiorus

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

Mr Jake

#11
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

Scorpiorus

It's more complicated since AGS hasn't functions like MoveCharacterPath() but for speeching and waiting. We have discussed this prbolem with juncmodule (here)

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


SMF spam blocked by CleanTalk