Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Wed 14/05/2003 20:15:03

Title: Getting an npc to walk back and forth
Post by: on Wed 14/05/2003 20:15:03
In my game I've got an NPC that needs to walk back and forth on loop until the player character uses a certain object on him. I can get the NPC to walk to a certain loacation on room load, but I can't get him to walk back and forth infinately. Any help appreciated
Title: Re:Getting an npc to walk back and forth
Post by: Jimi on Wed 14/05/2003 20:32:11
I am crap at looping, but try putting it in the repeatedly execute.
Title: Re:Getting an npc to walk back and forth
Post by: Andail on Wed 14/05/2003 23:31:30
I haven't tried this myself, but something like this could work - you want to move your character between say 120, 100 and 140, 200

function repeatedly_execute (){
if (character[NPC].x == 120){
MoveCharacter (NPC, 140, 200);
}
else if (character[NPC].x == 140){
MoveCharacter (NPC, 120, 100);
}
}

you should look up the functions before using them, as I'm a bit tired and not really focused atm.
There might also be a lot easier way.
Title: Re:Getting an npc to walk back and forth
Post by: on Mon 19/05/2003 20:01:11
Alright. I'm half way there.

Where should I paste that code? I pasted it to run this script...

if (character[DOG].x == 384){
MoveCharacter (DOG, 151, 152);
}
else if (character[DOG].x == 151){
MoveCharacter (DOG, 384, 156);
}
}

...into Repeatedly Execute but that just made DOG walk in place... So I tried pasting it in "Player enters screen (after fade-in)" and that made DOG walk to 151,152 but then stop.

Hmm... Any more help?
Title: Re:Getting an npc to walk back and forth
Post by: Scorpiorus on Mon 19/05/2003 20:27:36
 Just add if (character[DOG].walking == 0) statement. That's because if you run MoveCharacter() repeatedly it won't move (it will be starting again all the time). Checking for co-ordinate won't help as actual movement is started after a loop or something so the character position is not changed.

inside room's_repeatedly:

if (character[DOG].walking == 0) {
 if        (character[DOG].x == 384) MoveCharacter (DOG, 151, 152);
 else if (character[DOG].x == 151) MoveCharacter (DOG, 384, 156);
}

-Cheers
Title: Re:Getting an npc to walk back and forth
Post by: on Wed 21/05/2003 20:22:23
That doesn't seem to work either... the character just walks from 384,156 to 151,152 and stops.

Sorry for all the questions, I'm new to scripting.
Title: Re:Getting an npc to walk back and forth
Post by: Scorpiorus on Wed 21/05/2003 22:53:02
inside room's_repeatedly: ;)

-Cheers
Title: Re:Getting an npc to walk back and forth
Post by: on Wed 28/05/2003 22:42:31
I seem to be hopeless. Now it says that "inside room's_repeatedly:" is an incorrectly terminated character constant. I'd probably be able to fix the problem if I knew what that meant...
Title: Re:Getting an npc to walk back and forth
Post by: Scorpiorus on Wed 28/05/2003 23:03:16
You need to place it inside of the repeatedly execute function of this room. Goto interaction editor, add repeatedly execute interaction and choose run script option, next edit script and paste that code into:
if (character[DOG].walking == 0) {
if (character[DOG].x == 384) MoveCharacter (DOG, 151, 152);
else if (character[DOG].x == 151) MoveCharacter (DOG, 384, 156);
}

So when you'll open the room script it should look like:

function room_*() {  //* - editor replaces it with a latter
// script for room: Repeatedly execute
if (character[DOG].walking == 0) {
if (character[DOG].x == 384) MoveCharacter (DOG, 151, 152);
else if (character[DOG].x == 151) MoveCharacter (DOG, 384, 156);
}
}

 

let me know how it works ;)

-Cheers
Title: Re:Getting an npc to walk back and forth
Post by: on Thu 29/05/2003 21:45:05
Aha, I figured out what the problem was... but now I've got another one. When I enter the room with the dog walking for the first time, everything goes well. If I leave and come back, the dog is frozen ... hmm...
Title: Re:Getting an npc to walk back and forth
Post by: Scorpiorus on Thu 29/05/2003 22:17:04
You could place the next code into the player enters screen (after fade-in) interaction:

MoveCharacter (DOG, 151, 152);

so it would start moving when the player comes into the room...

-Cheers