wont display the right number[Solved]

Started by Icey, Mon 18/04/2011 23:16:46

Previous topic - Next topic

Icey

I have a GUI button that I use as a switch. If the players life falls below 0 I want the game to check to see if the button is visible an if it is I want it to restore 50% of life(HP) then I want the button to become invisible. However if the button is not visible I want the player to die.

Code: ags

if(playerHP <= 0){
   if(phinoxbuff.Visible == true){
    phinoxbuff.Visible = false;
  playerHP += 50;
  }
  
  else if(phinoxbuff.Visible == false)
  {
 CountDown.Stop();
 Dave.SayAt(8, 167, 320,"Dave:Is this it?.");
adeath.Play(eAudioPriorityHigh);
  Dave.Tint(204, 0, 0, 50, 100);
 chris.Tint(204, 0, 0, 50, 100);
 gameover.TweenTransparency(0.1, 100);
Dave.TweenTransparency(1.5, 100);
  chris.TweenTransparency(1.5, 100);
  aBoss1a.Stop();
  gameover.Visible = true;
  gameover.TweenTransparency(2.0, 0);
  Wait(19);
  RestartGame();
  }
}
  }

Khris

So, what exactly doesn't work as intended?

Judging from the title I guess something doesn't display the right number. Mind explaining what the problem is?

Icey

After the HP falls to 0 I want AGS to check and see if the button(phinoxbuff) is visible or not,

if true: give player +50hp | button becomes invisible

if false:go to death sequence

problem is, is that when the game gives the player +50 the hp still says 0 and the button is still visible.

Khris

There's nothing obvious wrong with the code you're using; the problem must lie somewhere else.
The thing is, you assume that the game gives the player +50 hp; do you know that for sure? Because if that line were called, so would the one that turns the button invisible.
We don't even know what function that code is inside.

This is simply an error somewhere else in your code, and we can't really help you without more info. You need to learn how to debug stuff like that yourself, btw.

Icey

 
Code: ags

 if(playerHP <= 1){
   if(phinoxbuff.Visible == true){
    phinoxbuff.Visible = false;
  playerHP += 50;
}
if(playerHP <= 0){
 CountDown.Stop();
 Dave.SayAt(8, 167, 320,"Dave:Is this it?.");
adeath.Play(eAudioPriorityHigh);
  Dave.Tint(204, 0, 0, 50, 100);
 muffy.Tint(204, 0, 0, 50, 100);
 gameover.TweenTransparency(0.1, 100);
Dave.TweenTransparency(1.5, 100);
  muffy.TweenTransparency(1.5, 100);
  aBoss1a.Stop();
  gameover.Visible = true;
  gameover.TweenTransparency(2.0, 0);
  Wait(19);
  RestartGame();
  }


Here is something I thought about try.

Khris

Wow, you changed 0 to 1 (which makes the player die if their health reaches 1) instead of
a) properly indenting the code
b) addressing anything I've said in my post.

Congrats.

Icey

a(If HP hits 1 or below it should give you 50% of HP)

b(If the HP hit 0 the after checking (A) then the player will die.)

Sephiroth

"won't display..." when you add +50 hp, are you updating the Label or whatever displays the HP? I mean like:

Code: ags

PlayerHP += 50;
HPLabel.Text = PlayerHP;


So this is supposed to be a revive buff that avoids death? On top of what Khris already mentioned I think it would be good to have some functions in your code:

Code: ags

function Attack(source, target)
{

  //walk to enemy or whatever
  //animate damage and attack

  ApplyDamage(source, target);

  if( targetHP <= 0 )
  {
    if( target == player && BuffButton.Visible == true )
    {
      ApplyBuff(Player, GIVE_50_HP);
      BuffButton.Visible = false;
      HPLabel.Text = playerHP;
    }
    else
    {
      ApplyDeath(target);
    }
  }

}


This should help keeping the main code clear, and then all you have to do is split the actions into several functions like I tried to demonstrate.

Btw, scripting and coding in general relies on strong logic and strict grammar,  you can't expect "the game" to do anything but follow your commands, if it doesn't display something, then you probably didn't ask the game to do it. I hope it helps.

Icey

#8
Yes it's a revive buff. However if I ask the game to set the PairHP.text = HP:50 then the label will display that however there are a lot of problems that way.



I don't  think the code you've shown can work for me right now. :(

Khris

According to the description of the second pic (why put it inside the screenshots, why not as text below them? This is a forum after all and now we can't quote it ::) see, that's the type of dumb stuff you pull all the time) the problem seems to be that either playerHP isn't decremented immediately after the enemy attacked or the function whose contents you've posted doesn't get called when it should.

But, repeating myself:
We don't even know what function that code is inside. Or when it is called.

If you don't learn how to properly ask for help (this includes proper reading, understanding and addressing of the replies), I will ignore your threads in the future.

Icey

#10
Oh, It's in side the obj inventory section.
Code: ags

-----------------------------------------------------------------------------------------------battle script--------------------------------
function Shiva_UseInv()
{

  //life or death-------------------------------------------------------------------------------------------<><><>
if(playerHP <= 1){
   if(phinoxbuff.Visible == true){
    phinoxbuff.Visible = false;
  playerHP += 50;
}
}
if(playerHP <= 0){
 CountDown.Stop();
 Dave.SayAt(8, 167, 320,"Dave:Is this it?.");
adeath.Play(eAudioPriorityHigh);
  Dave.Tint(204, 0, 0, 50, 100);
 muffy.Tint(204, 0, 0, 50, 100);
 gameover.TweenTransparency(0.1, 100);
Dave.TweenTransparency(1.5, 100);
  muffy.TweenTransparency(1.5, 100);
  aBoss1a.Stop();
  gameover.Visible = true;
  gameover.TweenTransparency(2.0, 0);
  Wait(19);
  RestartGame();
  }
  


}



Legend
My_hp reps the damage dealt to you
PlayerHp is a variable
PairHp is a label that displays your hP

I think that what you asking for.

ddq

My my, it sure is derp in here. I think it might be time to throw in the towel, Khris.

Khris

It's like a really complex riddle :)

Here's the gist of that function (properly indented, btw):

Code: ags
function Shiva_UseInv() {

  if(Dave.ActiveInventory == com1) {

  }
  else if(Dave.ActiveInventory == com4) {

  }

  //----------------------------------------------------------
  if(EnemyST <= 0){

  }

  //life or death-------------------------------------------------------------------------------------------<><><>
  if(playerHP <= 1){
    if(phinoxbuff.Visible == true){
      phinoxbuff.Visible = false;
      playerHP += 50;
    }
  }
  if(playerHP <= 0){
    RestartGame();
  }
  
  //--------------------------------------------------------------------------------------------------------------<><><>
  if(EnemyST >= 1){
    playerHP -= 50;
  }
}


As you can see, the life or death part is above the enemy's attack, i.e. if the player loses 50 HP and ends up having less than 2, the Phoenix stuff only kicks in the next time the function is called.

The order is supposed to be:

- attack enemy
- check if enemy is dead
- enemy attacks
- player's life or death handling

The warm, fuzzy feeling you're currently experiencing is either relief or pee.

Icey

Ohh, I had a small feeling it was the order. Thanks khris.

I got the last two mixed up.

monkey0506

Man, I never would have thought that the order in which you type commands makes a difference. I thought you could just type in every command in any order and it would automatically know what you mean!! Isn't that what a game engine is supposed to do?!? :-\

Icey

I know theres a order to things because I made the order work in each room, this way however is the right way of doing every thing.

SMF spam blocked by CleanTalk