Is it possible to disable a repeatedly execute function?

Started by Mouth for war, Tue 19/05/2009 15:06:26

Previous topic - Next topic

Mouth for war

Yeah maybe I'm stupid but it's better to ask to get it confirmed right? :D Is it possible to disable a repeatedly execute function? I have this gnome running around on one of my backgrounds picking up stuff from the ground and talks to himself...you're supposed to be a able to catch him but if you do that and remove him from the room the repeatedly execute function still runs and everything locks. The player can't move at all etc. So...if it's not possible to disable that function do you have any ideas how to get this to work? I looked in the manual but didn't find anything...
EDIT: Here's the code for it

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 = ANIMATIE;
     }

     // ANIMATE - Character has just stopped walking so now start the animation
     else if (GnomeState==ANIMATIE) {
          GnomeState = ANIMATING;
          cChar5.LockView (19);
          cChar5.Animate (1, 3);
          cChar5.UnlockView();
           int buk = Random(8);
    String sentence;
    if (buk == 0)
    {
      sentence = "Not enough, need more";
    }
    if (buk == 1)
    {
      sentence = "It's a shitty job but someone's gotta do it";
    }
    if (buk == 2)
    {
      sentence = "I'm getting tired of this";
     
    }
     if (buk == 3)
    {
      sentence = "This is so goddamn boring";
     
    }
     if (buk == 4)
    {
      sentence = "I want to sleep now";
     
    }
     if (buk == 5)
    {
      sentence = "Damn Howard, making me do this on my day off ";
     
    }
    if (buk == 6)
    {
      sentence = "I'm gonna complain to the union";
     
    }
     if (buk == 7)
    {
      sentence = "Is there no end to this?";
     
    }
    if (buk == 8)
    {
      sentence = "I wish I was home now";
        }
       
    cChar5.SayBackground(sentence);
}
               

     // 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;   
    }
if (cChar5.IsCollidingWithChar(cEgo) == 1)
                   cChar5.SayBackground ("Out of my way you tall bastard");}
                   
mass genocide is the most exhausting activity one can engage in, next to soccer

Vince Twelve

#1
Just put everything inside the RepEx function that you want to stop inside an if statement.

Code: ags

bool repExEnabled=true;

function room_RepExec()
{
  if(repExEnabled){
    int ran;


     // MOVE - Character is has finished animating, start him on his journey
     if (GnomeState==MOVE) {
          GnomeState = MOVING;
    //...
    //...more stuff here
    //...
  }

  //...more stuff here that you don't want to disable...

}

Then, when you want to stop running those statements.  Change repExEnabled to false.

I didn't read closely through your code, but this is one quick and easy way to do what you're looking for.

Mouth for war

I tried but it didn't help...I got the gnome to stop moving but his walkinganimation kept playing anyway and the game became very slow...the player moved much much slower. Oh well, guess i'll have to use plan B instead :D thanks anyway!
mass genocide is the most exhausting activity one can engage in, next to soccer

Khris

Could you post the rep_ex? And please use code tags, just quote Vince's post to see how it's done.

Matti

Oh, and just to let you know - in case, you don't  - you can shorten this piece of code:

Code: ags

    if (buk == 0)
    {
      sentence = "Not enough, need more";
    }
    if (buk == 1)
    {
      sentence = "It's a shitty job but someone's gotta do it";
    }
    if (buk == 2)
    {
      sentence = "I'm getting tired of this";     
    }


..using this code here. You don't need {} when there's only one command after the if-statement.

Code: ags

if (buk==0) sentence= "Not enough, need more";
if (buk==1) sentence= "It's a shitty job but someone's gotta do it";
if (buk==2) sentence= "I'm getting tired of this";

SMF spam blocked by CleanTalk