strange behaviour of a walking NPC

Started by Tolman, Fri 04/02/2011 00:28:42

Previous topic - Next topic

Tolman

I'm trying to make an NPC enter the room, walk to a chair and sit. After many trials & errors it works, sort of, but the character keeps walking on place for a few seconds before moving. I wonder why.
I put the walking script in globalscript.asc, after I found out that in the room script it would make the character endlessly walk on place.

Here's the globalscript:

 
    if (cEgo.Room == 4)
    {cChar3.ChangeRoom(4, 607, 465);
   cChar3.Walk(407, 358, eNoBlock, eAnywhere);


and here's the room code:
bool miss_arrived = false;


function room_RepExec()
{
     if (cChar3.Room == 4) 
   {
     
      if (!cChar3.Moving && !miss_arrived) 
      {
        cChar3.FaceLocation (cChar3.x, cChar3.y+1);
        cChar3.LockView(11);
        cChar3.Animate(1, 5, 0, eNoBlock);
        miss_arrived = true;
      
      }
   }


Matti

Code: ags

    if (cEgo.Room == 4)
    {cChar3.ChangeRoom(4, 607, 465);
    cChar3.Walk(407, 358, eNoBlock, eAnywhere);



This is constantly (40 times a second) telling Char3 to change the room and walk. That should definitely cause problems, I wonder why he even moves. Use a variable or the Game.DoOnceOnly function to let it only happen once.

Tolman

The actions of every NPC are set by a timer, so perhaps this is the reason it does work, more or less.
I'll try to apply your suggestion.

cianty

If you want to use the effect again later, try using the Moving attribute or even the x and y coordinates. Also you could use boolean to determine whether he has reached his goal. Or if he is supposed to do a lot of stuff you could use an 'int' and have that save the various states of the cutscene.

int mode = 0;
-----------------------
if (cEgo.Room == 4 && !cChar3.Moving && mode == 0)
{
  cChar3.ChangeRoom(4, 607, 465);
  cChar3.Walk(407, 358, eNoBlock, eAnywhere);
  mode++;
}

Depending on the situation and the context I'd use a combination or just some of the many possibilities.
The important thing is to remember what Matt pointed out: You are constantly telling the character to move. So make sure that the 'if' condition triggers only once.
ca. 70% completed

Tolman

I tried with cianty's code, but in the room script. Now the character, while walking, flickers for a few seconds, and then doesn't move to the desired spot, even if she turns to face down. She doesn't change the animation, anyway.
It might be useful to add that every character, except for the player, changes room according to a timetable in the global script.


bool miss_arrived = false;
int mode = 0;

function room_RepExec()
{
     if (cChar3.Room == 4 &&  mode == 0)
   {
     
     
     cChar3.Walk(407, 358, eNoBlock, eAnywhere);
      mode++;
      }
      if (!cChar3.Moving && mode>0)
      {
        cChar3.FaceLocation (cChar3.x, cChar3.y+1);
        cChar3.LockView(11);
        cChar3.Animate(1, 5, 0, eNoBlock);
        miss_arrived = true;
      
      }


Dualnames


=Globalscript=
Code: ags

function on_event(EventType event, int data) {
if ((event==eEventRoomBeforeFadeIn) && (data == 4))    {
 cChar3.ChangeRoom(4, 607, 465);
}
}


-Variables needed to be declared-
Code: ags

bool miss_arrived = false;
int checktime; 
//both can be just placed on the start of the room script


=Room repeatedly execute=
Code: ags

function room_RepExec(){
if ((miss_arrived)  && (cChar3.Room == 4))  {
checktime++;

     if (checktime==50) {
       cChar3.Walk(407, 358, eNoBlock, eAnywhere);
     }
     if (checktime==500)       {//Ideally this means that the character has reached destination
     cChar3.FaceLocation (cChar3.x, cChar3.y+1);
     cChar3.LockView(11);
     cChar3.Animate(1, 5, eOnce, eNoBlock, eForwards);
    }
   }
}


There may be a stupid parse error somewhere.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk