Oxygen Meter trouble

Started by R4L, Sat 26/02/2005 06:31:20

Previous topic - Next topic

R4L

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.

Pumaman

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.

DoorKnobHandle

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...
Code: ags

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.
Code: ags

player_inwater = 1;


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

player_inwater = 0;


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

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...

R4L

#3
Can you tell me how to get the slider to go with the script?

Ashen

I think you want SetSliderValue(GUI, OBJECT, VALUE), e.g.
Code: ags

if (player_inwater == 1)
{
   if (counter < 99)
      counter++;
   else
   {
      player_air--;
      SetSliderValue (AIRGUI, 0, player_air);
      counter = 0;
   }
}
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk