Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Sun 14/06/2009 18:24:44

Title: setx and y coordinates not working.
Post by: geork on Sun 14/06/2009 18:24:44
 Hey All!!
  I have a question concerning character relocation. I have a region (1) where a character will follow you in, but if the varial zomhp4 is equal to 0, then he should move back to another position.

if(zomhp4 <= 0){
    cZom4.UnlockView();
    region[1].Enabled = false;
    cZom4.StopMoving();
    zomhp4 = 10;
   cZom4.x = 575;
   cZom4.y = 200;
  }

  the only problem is that the character remains in the same position as he stopped in (which he does if the zomhp4 = 0), he doesn't go to the coordinates given
  am i doing something wrong? (answer: yes), and how can I correct it?
   Thanks
Title: Re: setx and y coordinates not working.
Post by: RickJ on Sun 14/06/2009 19:27:09
The StopMoving command does not take effect until the script completes.  Inserting a Wait() command  gives the engine an opportunity to stop the character's movement before executing the rest of the script.

if(zomhp4 <= 0){
    cZom4.UnlockView();
    region[1].Enabled = false;
    cZom4.StopMoving();
    Wait(1);                                // Try adding a wait here
    zomhp4 = 10;
   cZom4.x = 575;
   cZom4.y = 200;
  }
Title: Re: setx and y coordinates not working.
Post by: geork on Sun 14/06/2009 19:40:19
thanks, but the character Zom4 just flashes once on his designated place before flashing back to the place zomhp4 was reduced to 0.
  maybe the region code could help:
   
function region1_Standing()
{
  if(cZom4.View != 6){
cZom4.FollowCharacter(cEgo, 0, 0);
  }
  if(cZom4.View == 6){
    cZom4.FollowCharacter(null);
  }
}

cZom view will equal 6 when zomhp4 is equal to 0. the region covers the entire room, if that helps.
  thanks
Title: Re: setx and y coordinates not working.
Post by: geork on Sun 14/06/2009 20:13:41
 okay, something strange has just happened:
  I have 4 cZom characters, when one of them has their zomhp (1,2,3 or 4) depleted to 0, that character does exactly what it's supposed to, but when another has it's zomhp depleted, it flashes to where it should be, then returns and keeps following. Not only that, but the one that's meant to be in the corner suddenly starts to chase again:
here's the code:
 
if(zomhp <= 0){
    cZom.UnlockView();
    region[1].Enabled = false;
    cZom.StopMoving();
    Wait(40);
    zomhp = 10;
   cZom.x = 250;
   cZom.y = 15;
  }
  if(zomhp2 <= 0){
    cZom2.UnlockView();
    region[1].Enabled = false;
    cZom2.StopMoving();
    Wait(40);
    zomhp2 = 10;
   cZom2.x = 10;
   cZom2.y = 205;
  }
  if(zomhp3 <= 0){
    cZom3.UnlockView();
    region[1].Enabled = false;
    cZom3.StopMoving();
    Wait(40);
    zomhp3 = 5;
   cZom3.x = 310;
   cZom3.y = 430;
  }
  if(zomhp4 <= 0){
     cZom4.UnlockView();
    region[1].Enabled = false;
    cZom4.StopMoving();
    Wait(40);
    zomhp4 = 10;
   cZom4.x = 580;
   cZom4.y = 220;
   region[1].Enabled = true;
  }

  I find this unexplainable
  Thanks
Title: Re: setx and y coordinates not working.
Post by: geork on Sun 14/06/2009 21:03:31
okay, peeps, problem solved, I merely had to change the UlockView to the end, but thx 4 the wait bit, that really helped ;)