Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: R4L on Sat 26/02/2005 06:31:20

Title: Oxygen Meter trouble
Post by: R4L on Sat 26/02/2005 06:31:20
I have this problem. I am creating a scenario in my game where you have limited breaths of air. A meter shows when your character has to breathe more air. I have 2 GUI's, 1 with a slider to show how much air you hold and the other GUI has a button that you can press to take another breath. I want the slider on GUI 1 to go down as your character loses air but with the code I put in the global script the slider goes down way too fast. I tried to use a Wait command but it interferes with the gameplay. Can anyone help me please? Thank you.
Title: Re: Oxygen Meter trouble
Post by: Pumaman on Sat 26/02/2005 12:27:35
You can use SetTimer and then IsTimerExpired in repeatedly_execute so that you only move the slider down once a second, or whatever timing you're after.
Title: Re: Oxygen Meter trouble
Post by: DoorKnobHandle on Sat 26/02/2005 12:35:28
A different approach to your problem would be this:

You add a counter variable, a player_inwater and a player_air variable to your script file...

int counter = 0;
int player_inwater = 0;
int player_air = 100;


Then if the player is in the room with the water, you set player_inwater to 1.

player_inwater = 1;


If the player is not in that room, you set it to 0.

player_inwater = 0;


And in your rep_execute function you add the counter, which executes commands only every 100th game cycle:

if (player_inwater == 1)
{
   if (counter < 99)
Ã,  Ã,    counter++;
   else
   {
Ã,  Ã,    player_air--;
Ã,  Ã,    counter = 0;
   }
}


That's about it, I think. I wrote this off the top of my head, so I may have made a mistake, although I read it after writing to check.

This approach decrements the air the player has every 100th game cycle...

I personally like this way more than using dirty timers...
Title: Re: Oxygen Meter trouble
Post by: R4L on Sun 27/02/2005 17:29:58
Can you tell me how to get the slider to go with the script?
Title: Re: Oxygen Meter trouble
Post by: Ashen on Mon 28/02/2005 08:37:24
I think you want SetSliderValue(GUI, OBJECT, VALUE), e.g.

if (player_inwater == 1)
{
   if (counter < 99)
      counter++;
   else
   {
      player_air--;
      SetSliderValue (AIRGUI, 0, player_air);
      counter = 0;
   }
}