doing stuff in the background (SOLVED)

Started by Mouth for war, Wed 06/05/2009 14:28:49

Previous topic - Next topic

Mouth for war

Ok here´s my little problem. I have a small gnome on one of the pictures and i want him to walk around the screen and pick up stuff here´s the code but he doesnät walk...the only thing that happens is that the gnome stands still on the same place and plays the picking up animation over and over again a little help would be appreciated :D here´s the code i made

function room_RepExec()
{
int ran=Random(7);
if (ran==0)
{cChar5.Walk(633, 377);
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}
else if (ran==1)
{cChar5.Walk(200, 350);
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}

else if (ran==2)
{cChar5.Walk(427, 287);
cChar5.LockView (19);
cChar5.Animate (2, 3);
cChar5.UnlockView();
}
else if (ran==3)
{cChar5.Walk(127, 500);
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}
else if (ran==4)
{cChar5.Walk(600, 300);
cChar5.LockView (19);
cChar5.Animate (2, 3);
cChar5.UnlockView();
}
else if (ran==5)
{cChar5.Walk(127, 500);
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}
else if (ran==6)
{cChar5.Walk(312, 375);
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}
else
{cChar5.Walk(72, 418);
cChar5.LockView (19);
cChar5.Animate (2, 3);
cChar5.UnlockView();}
}
mass genocide is the most exhausting activity one can engage in, next to soccer

Hudders

Each of your walk commands needs to include the eBlock parameter.

eg:

Code: ags
function room_RepExec()
{
int ran=Random(7);
if (ran==0)
{cChar5.Walk(633, 377,eBlock);
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}


etc

Mouth for war

yeah i thought so. Is that the only possibility? I really don't want the game to pause when he walks around. The room will be almost unplayable then
mass genocide is the most exhausting activity one can engage in, next to soccer

Hudders


Mouth for war

yeah but isn't that´s only for doing animations in background? that wouldn't work for the guy walking around right?
mass genocide is the most exhausting activity one can engage in, next to soccer

Hudders

You could always try something like:

Code: ags

function room_RepExec()
{
int ran=Random(7);
if (ran==0)
{cChar5.Walk(633, 377);
while (cChar5.Moving)
{
Wait(1);
}
cChar5.LockView (19);
cChar5.Animate (1, 3);
cChar5.UnlockView();
}


I don't know for sure that would work, but logically it should wait until the character has finished moving before doing the animation.

RickJ

#6
Don't use the eBlock option.  Instead check to see that the character has stopped moving before sending him to a new location. 

Code: ags

int GnomeState = 0;
#define MOVE          0
#define MOVING      1
#define ANIMATIE    2
#define ANIMATING 3

function room_RepExec() {
     int ran;

     // MOVE - Character is has finished animating, start him on his journey
     if (GnomeState==MOVE) {
          GnomeState = MOVING;
          ran = Random(7);
          if (ran==0) cChar5.Walk(633, 377);
         else if (ran==1) cChar5.Walk(200, 350);
         else if (ran==2) cChar5.Walk(427, 287);
         else if (ran==3) cChar5.Walk(127, 500);
         else if (ran==4) cChar5.Walk(600, 300);
         else if (ran==5) cChar5.Walk(127, 500);
         else if (ran==6) cChar5.Walk(312, 375);
         else cChar5.Walk(72, 418);
     }

     // MOVING - Character is moving, wait for movement to stop 
     else if (GnomeState==MOVING) {
          if (!cChar5.Moving) GnomeState = ANIMATE;
     }

     // ANIMATE - Character has just stopped walking so now start the animation 
     else if (GnomeState==ANIMNATE) {
          GnomeState = AN IMATING;
          cChar5.LockView (19);
          cChar5.Animate (1, 3);
          cChar5.UnlockView();
     }

     // ANIMATING - Character is animating, wait for animation to stop 
      else if (GnomeState==ANIMATING) {
          if (!cChar5.Animating) GnomeState = MOVE;
     }

     // DEFAULT - Default state is MOVE
     else {
          GnomeState = MOVE;   
     }


[edit]
The problem with Hudders approach is that the character is moved/animated by the run-time engine and not by the room script.   The room script only sends a command to the run-time so it knows what action to execute.   But the run-time does not do anything until the all scripts are completed for the current game scan.   

Note also that my interpretation of your original code is that you want the character  to walk to a random point, perform an animation and then re[peat the process.   

Mouth for war

THANK YOU!!! :D that worked. Thank you very much
mass genocide is the most exhausting activity one can engage in, next to soccer

SMF spam blocked by CleanTalk