Getting an npc to walk back and forth

Started by , Wed 14/05/2003 20:15:03

Previous topic - Next topic

iatw

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

Jimi

I am crap at looping, but try putting it in the repeatedly execute.

Andail

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.

iatw

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?

Scorpiorus

 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

iatw

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.

Scorpiorus


iatw

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

Scorpiorus

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

iatw

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

Scorpiorus

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

SMF spam blocked by CleanTalk