Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Glenjamin on Sat 29/08/2015 22:44:25

Title: Making a 3 life health system work. [SOLVED]
Post by: Glenjamin on Sat 29/08/2015 22:44:25
I'm currently working on a game where the player takes 3 hits to kill him and end the game.

So logically, I set up a variable for health called "health" and se it's starting value to 3.

Then I set up the code to play the death animations when the player is killed.  This is currently in the Room_load funtion

Code (ags) Select

if (health == 0)
  {
      player.ChangeView(1);
        player.Animate(2, 5, eRepeat, eNoBlock);
        Wait(50);
     aScream.Play(eAudioPriorityHigh, eOnce);
     player.Animate(1, 5, eRepeat, eBlock);
    }


Then, there's three events controlling when the player gets damaged.

This is when a bowling ball lands on his head.
Code (ags) Select


if (player.IsCollidingWithObject(oObject1))
{
player.StopMoving();
aRambling_ball.Stop();
oObject1.Visible = false;
player.ChangeView(8);
player.Animate(0, 5, eOnce, eBlock);
health -= 1;
oinactiveball.Visible = true;
Wait(100);
   player.ChangeView(4);
 
    ctalk.Walk(2241, 143, eNoBlock, eAnywhere);
}


This is when he gets a door slammed on him.

Code (ags) Select


if ((atshop == true) && (running == true))
{
  aAccounting2.Stop();
  player.ChangeView(8);
  player.Animate(1, 5, eOnce, eBlock, eForwards);
  player.ChangeView(7);
  player.Animate(3, 5, eOnce, eBlock);
   Wait(100);
   player.ChangeView(4);
   health -= 1;
    ctalk.Walk(3290, 143, eNoBlock, eAnywhere);
  }


And finally, when he gets hit in the head with a flower pot.

Code (ags) Select


if (player.IsCollidingWithObject(oactivepot))
{
player.StopMoving();
aAccounting2.Stop();
oactivepot.Visible = false;
player.ChangeView(8);
player.Animate(0, 5, eOnce, eBlock);

obrokepot.Visible = true;
Wait(100);
   player.ChangeView(4);
   health -= 1;
    ctalk.Walk(3290, 143, eNoBlock, eAnywhere);
}



Despite executing all 3 of these events perfectly in the game, The death animation doesn't happen. Thanks for all the help you guys! :smiley:
Title: Re: Making a 3 life health system work.
Post by: Mandle on Sat 29/08/2015 23:09:49
I think your problem is that the code to check if Health == 0 is in Room Load. This means that the game only checks every time the player enters the room.

It should be either immediately following the code that subtracts the health OR in Repetedly Execute if you want death to happen the same game-loop that Health hits zero.

Also:

health --;

should be fine for subtracting a single health each time. Not sure if this is tied to the problem though. Probably not.
Title: Re: Making a 3 life health system work. [SOLVED]
Post by: Glenjamin on Sun 30/08/2015 00:22:07
Thank you so much! my game is functional again thanks to you!