Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

addition is weird

New Here ,
Jan 06, 2016 Jan 06, 2016

Hello, i'm having a major problem, i simply have no idea what is wrong, but i do know it's not supposed to be like this here's the relevant code:

Player stats

Player[1] = [30] //Max HP

Player[2] = [10] //Max MP

Player[3] = [2] //Num HP pots

Player[4] = [2] //Num MP pots

/*

Other insignificant values

*/

Player[9]  = [30] //Current HP

Player[10] = [30] //Current MP

Faulty part of function PlayerTurn();

function Hp (e: MouseEvent) {

     if (Player[3] > 0) //Checking if player has Health potions

     {

          trace(Player[1]); //outputs to 30

          trace(Player[9]); //outputs to 30

          if (Player[1] == Player[9]) //Apparently this isn't equal, it should be but isn't. I think this may be related to the issue, but that is further down.

          {

               //OUTPUT TEXT

          }

          else

          {

               Player[3]--; //Reducing number of health potions

               PlayerHeal = Math.round(Player[1] * 0.5); //Neccesary middle operation, i'm outputting this in a textbox later.

               Player[9] = Player[9] + PlayerHeal; //This is were the problem lies

               /*

                 This is where the problem lies

                 you see; the answer to this is 3015

                 it SHOULD be 45 and i have no clue why.

                 if i subtract 1 then add 1 it becomes correct,

                 but i want to know why this happens.

               */

               //RECALCULATE HEALTH BAR

               //OUTPUT TEXT

          }

     }

     //OUTPUT TEXT

}

I'm still quite new in AS3, but this goes against everything I've learned, i can't really figure out what's wrong. but i do know 3030HP is wrong, when it should be 45.

TOPICS
ActionScript
335
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 06, 2016 Jan 06, 2016

Player[9] = Number(Player[9]) + Number(PlayerHeal); // Convert the contents to numbers.

Translate
Enthusiast ,
Jan 06, 2016 Jan 06, 2016

Player[9] = Number(Player[9]) + Number(PlayerHeal); // Convert the contents to numbers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2016 Jan 06, 2016

Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 06, 2016 Jan 06, 2016
LATEST

You're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines