Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mouth for war on Wed 06/05/2009 14:28:49

Title: doing stuff in the background (SOLVED)
Post by: Mouth for war on Wed 06/05/2009 14:28:49
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();}
}
Title: Re: doing stuff in the background
Post by: Hudders on Wed 06/05/2009 14:32:45
Each of your walk commands needs to include the eBlock parameter.

eg:

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
Title: Re: doing stuff in the background
Post by: Mouth for war on Wed 06/05/2009 14:36:19
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
Title: Re: doing stuff in the background
Post by: Hudders on Wed 06/05/2009 14:40:54
Might help (http://www.americangirlscouts.org/agswiki/Scripting%2C_Code_%26_Interaction#Having_a_character_continuously_animated_in_the_background)
Title: Re: doing stuff in the background
Post by: Mouth for war on Wed 06/05/2009 14:43:03
yeah but isn't that´s only for doing animations in background? that wouldn't work for the guy walking around right?
Title: Re: doing stuff in the background
Post by: Hudders on Wed 06/05/2009 14:50:40
You could always try something like:


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.
Title: Re: doing stuff in the background
Post by: RickJ on Wed 06/05/2009 15:16:04
Don't use the eBlock option.  Instead check to see that the character has stopped moving before sending him to a new location. 


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.   
Title: Re: doing stuff in the background
Post by: Mouth for war on Wed 06/05/2009 15:31:03
THANK YOU!!! :D that worked. Thank you very much