Idle problem with Bernie's 8 Direction Movement module

Started by slavec, Sun 09/02/2014 03:22:06

Previous topic - Next topic

slavec

Hey!

I have a problem with the idle animation, when using Bernie's 8 Direction Movement module.
The idle freezes on the first frame.
I have tried:   cEgo.SetIdleView(4, 0);  ,but with no luck.

I think this is the code that's freezing it:
Code: ags

//animations

  if (thrust==0){

    if (walkingani>0){
      if ((xm!=0)||(ym!=0)) {if (player.View!=walkingani) {player.LockView(walkingani);
      player.Animate(0,walkanispeed, eRepeat, eNoBlock, eForwards);}}

      if ((xm==0)&&(ym==0)) {player.UnlockView();}
    }
  }


slavec

Just to make it clear:
What I want is for the character to animate the idle when standing still. Loop without a delay.
Now with the module, the idle is always stuck on the first frame. And when I disable the module, the animation works as it should.
Otherwise the module is super for my project.

Here is the whole Bernie-code:

Code: ags

// Main script for module '8 Direction Movement'

//required values

int xm;
int ym;
int xspeed=38;
int yspeed=38;
int xwidth=5;
int ywidth=5;
int slide=8;
int a;
int c;
int dir;
int diagslowdown=1;
int walkanispeed=1;
int thrust;
int walkingani=2;
int disablemove;
int nodirset;
int eightdir;

static function EightDir::SetSpeed(int x, int y) {
  xspeed = x;
  yspeed = y;
}

static function EightDir::SetSize(int x, int y) {
  xwidth = x;
  ywidth = y;
}

static function EightDir::WalkViewSpeed(int speed) {
  walkanispeed = speed;
}  

static function EightDir::SetWalkView(int view) {
  walkingani = view;
}  

static function EightDir::SetSlide(int value) {
  slide = value;
}  

static function EightDir::Disable(bool value) {
  disablemove = value;
}  

static function EightDir::NoDirSet(bool value) {
  nodirset = value;
}  

static function EightDir::DiagSlow(bool value) {
  diagslowdown = value;
}  

static function EightDir::Thrust(int x, int y) {
  xm=x;
  ym=y;  
  thrust=1;
}  

static function EightDir::EightLoopsMode(bool value) {
  eightdir = value;
}

static function EightDir::IsMoving() {
  if ((xm!=0)||(ym!=0)) {return 1;}
  if ((xm==0)&&(ym==0)) {return 0;}
}

static function EightDir::IsThrusting() {
  return thrust;
}


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here

int up=0;
int down=0;
int left=0;
int right=0;

  if ((IsInterfaceEnabled()==1)&&(IsGamePaused()==0)) {

    if (IsKeyPressed(68)==1) {right=1;}
    if (IsKeyPressed(65)==1) {left=1;}
    if (IsKeyPressed(83)==1) {down=1;}
    if (IsKeyPressed(87)==1) {up=1;}
  }


  if ((IsInterfaceEnabled()==0)||(disablemove==1)) {xm=0;ym=0;}

  if ((player.Moving==0)&&(IsInterfaceEnabled()==1)&&(IsGamePaused()==0)&&(disablemove==0)) {

    int b=0;

    if ((xm==0) && (ym==0)) {thrust=0;}


    //moving values

      while (b<slide){

        if (thrust==0){

          if ((right==1) && (xm < xspeed))  {xm=xm+1;}   //right
          if ((left==1) && (xm > xspeed*(-1)))  {xm=xm-1;}   //left

          if ((down==1) && (ym < yspeed))  {ym=ym+1;}   //down
          if ((up==1) && (ym > yspeed*(-1)))  {ym=ym-1;}   //up

          if ((left==0) && (right==0) && (xm>0))  {xm=xm-1;}
          if ((left==0) && (right==0) && (xm<0))  {xm=xm+1;}

          if ((up==0) && (down==0) && (ym>0))  {ym=ym-1;}
          if ((up==0) && (down==0) && (ym<0))  {ym=ym+1;} 
        
        }  

      if (thrust==1) {
        if (xm > 0){xm=xm-1;}
        if (xm < 0){xm=xm+1;}
        if (ym > 0){ym=ym-1;}
        if (ym < 0){ym=ym+1;}
      }

    //slowdown

    if (thrust==0){
      if (xm > xspeed){xm=xm-1;}
      if (xm < xspeed*(-1)){xm=xm+1;}
      if (ym > yspeed){ym=ym-1;}
      if (ym < yspeed*(-1)){ym=ym+1;}
    }

  b=b+1;
  }

  //diagslowdown

  if (diagslowdown==1){

    int slow=0;
    while (slow <slide+1){

     if ((right==1)&&(down==1)) {
       if (xm>(xspeed*70)/100) {xm=(xm*70)/100;}
       if (ym>(yspeed*70)/100) {ym=(ym*70)/100;}
     }

     if ((left==1)&&(down==1)) {
       if (xm<((xspeed*70)/100)*(-1)) {xm=((xspeed*70)/100)*(-1);}
       if (ym>(yspeed*70)/100) {ym=(ym*70)/100;}
     }

     if ((left==1)&&(up==1)) {
       if (xm<((xspeed*70)/100)*(-1)) {xm=((xspeed*70)/100)*(-1);}
       if (ym<((yspeed*70)/100)*(-1)) {ym=((yspeed*70)/100)*(-1);}
     }

     if ((right==1)&&(up==1)) {
       if (xm>(xspeed*70)/100) {xm=(xm*70)/100;}
       if (ym<((yspeed*70)/100)*(-1)) {ym=((yspeed*70)/100)*(-1);}
     }
   slow=slow+1;
   }
  }

  //right

  int loop=0;

  if (xm>0){

    while (loop <xm) {
      a=a+1;
      if (a>10) {a=0;}
      if (a==5){
        player.x = player.x +xwidth;
        if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())>0) {player.x=player.x +1;}
        player.x = player.x -xwidth;
      }
    loop=loop+1;
    }
  }


  //left

  loop=0;

  if (xm<0){

    while (loop > xm) {
      a=a+1;
      if (a>10) {a=0;}
      if (a==5){
        player.x = player.x -xwidth;
        if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())>0) {player.x=player.x -1;}
        player.x = player.x +xwidth;
      }
    loop=loop-1;
   }
  }


  //down

  loop=0;

  if (ym>0){

    while (loop <ym) {
      c=c+1;
      if (c>10) {c=0;}
      if (c==5){
        player.y = player.y +ywidth;
        if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())>0) {player.y=player.y +1;}
        player.y = player.y -ywidth;
      }
    loop=loop+1;
    }
  }


  //up

  loop=0;

  if (ym<0){
    while (loop >ym) {
      c=c+1;
      if (c>10) {c=0;}
      if (c==5){
        player.y = player.y -ywidth;
        if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())>0) {player.y=player.y -1;}
        player.y = player.y +ywidth;
      }
    loop=loop-1;
    }
  }


  //outpush

  player.x = player.x -xwidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.x=player.x +1;}
  player.x = player.x +xwidth;

  player.x = player.x +xwidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.x=player.x -1;}
  player.x = player.x -xwidth;

  player.y = player.y -ywidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.y=player.y +1;}
  player.y = player.y +ywidth;

  player.y = player.y +ywidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.y=player.y -1;}
  player.y = player.y -ywidth;

  //outpush #2

  player.y = player.y -ywidth;

  player.x = player.x -xwidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.x=player.x +1;}
  player.x = player.x +xwidth;

  player.y = player.y +ywidth;
  player.y = player.y +ywidth;

  player.x = player.x -xwidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.x=player.x +1;}
  player.x = player.x +xwidth;

  player.y = player.y -ywidth;



  player.y = player.y -ywidth;

  player.x = player.x +xwidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.x=player.x -1;}
  player.x = player.x -xwidth;

  player.y = player.y +ywidth;

  player.y = player.y +ywidth;

  player.x = player.x +xwidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.x=player.x -1;}
  player.x = player.x -xwidth;

  player.y = player.y -ywidth;



  player.x = player.x +xwidth;

  player.y = player.y -ywidth;
  if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.y=player.y +1;}
  player.y = player.y +ywidth;

  player.x = player.x -xwidth;



  player.x = player.x -xwidth;

  player.y = player.y -ywidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.y=player.y +1;}
  player.y = player.y +ywidth;

  player.x = player.x +xwidth;



  player.x = player.x -xwidth;

  player.y = player.y +ywidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.y=player.y -1;}
  player.y = player.y -ywidth;

  player.x = player.x +xwidth;
 
 
  
  player.x = player.x +xwidth;

  player.y = player.y +ywidth;
    if (GetWalkableAreaAt(player.x - GetViewportX(),player.y - GetViewportY())==0) {player.y=player.y -1;}
  player.y = player.y -ywidth;

  player.x = player.x -xwidth;

 
  //animations

  if (thrust==0){

    if (walkingani>0){
      if ((xm!=0)||(ym!=0)) {if (player.View!=walkingani) {player.LockView(walkingani);
      player.Animate(0,walkanispeed, eRepeat, eNoBlock, eForwards);}}

      if ((xm==0)&&(ym==0)) {player.UnlockView();}
    }
  }


  //set direction

  if (eightdir==0){

    if ((left==1)||(right==1)||(up==1)||(down==1)){

      if (thrust==0){

        if (ym>0) {if ((left==0)&&(right==0))  {dir=0;}}
        if (xm<0) {if ((up==0)&&(down==0))  {dir=1;}}
        if (xm>0) {if ((up==0)&&(down==0))  {dir=2;}}
        if (ym<0) {if ((left==0)&&(right==0))  {dir=3;}}

        if ((ym>0) && (player.Loop==3))  {dir=0;}
        if ((ym<0) && (player.Loop==0))  {dir=3;}
        if ((xm>0) && (player.Loop==1))  {dir=2;}
        if ((xm<0) && (player.Loop==2))  {dir=1;}
      }
    }
  }


  if (eightdir==1){

    if ((left==1)||(right==1)||(up==1)||(down==1)){

      if (thrust==0) {
    
        if ((xm>0)&&(ym==0)) {dir=2;}
        if ((xm<0)&&(ym==0)) {dir=1;}
        if ((xm==0)&&(ym>0)) {dir=0;}
        if ((xm==0)&&(ym<0)) {dir=3;}

        if ((xm>0)&&(ym>0)) {dir=4;}
        if ((xm<0)&&(ym>0)) {dir=6;}
        if ((xm<0)&&(ym<0)) {dir=7;}
        if ((xm>0)&&(ym<0)) {dir=5;}
      }
    }
  }


  if ((player.Moving==0)&&(nodirset==0)) {player.Loop=dir;}
  }


  if (player.Moving==1) {dir=player.Loop;}

  if (nodirset>0) {dir=player.Loop;}

  if (IsInterfaceEnabled()==0) {dir=player.Loop;}

}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


Ghost

The thing is, idling is a build-in AGS function designed to work with vanilla AGS. The module overrides this behavior by constantly checking and setting loops, and this also affect the idleview.
You need a workaround here, one possibility I see is to add a check if the player is not currently in their idle view before those changes are applied.

Daniel Eakins

We all have our time machines, don't we?

slavec

Thanks for the replys.
I am a beginner with AGS and scriping, so I don't really know how to manage that.
Can I get some direction on what code to use?

ManicMatt

#5
Hello all, I am back! I wouldn't normally necro a post so old but it perfectly describes the issues I am having. I see nobody ever came up with a solution but maybe users around now may be able to help? Thanks. Worse than no idle animations, is that setting animations for the character doesn't work at all and is overidden by the module.

Update:

It's not exactly ideal, but so far this seems to work as a work around for animations (except when idle), should anyone else have this conundrum in the future and this isn't directly solved.

I created a "fake" main character, and have them set to be invisible and always be on the same spot/location as the main character:

Code: ags
  cFake.FollowCharacter(cEgo, FOLLOW_EXACTLY, 0);
  cFake.Transparency =100;

Then, when I need the character to talk, for instance:
Code: ags
cFake.FaceDirection(eDirectionUp);
    cEgo.Transparency = 100;
    cFake.Transparency = 0;
    cFake.Say("It worked!");
    cFake.Say("Bloody hell.");
    cEgo.Transparency = 0;
    cFake.Transparency = 100;

While I feel quite clever to have thought of this.. it's a pain in the bum.
   

SMF spam blocked by CleanTalk