Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:14:30+00:00 2026-06-05T00:14:30+00:00

I am writing a small game for a bit of fun. It’s a simple

  • 0

I am writing a small game for a bit of fun. It’s a simple turn based battle game kind of like Pokemon style battles but with stupid/joke characters.

I have some stuff on the main timeline for user interface but everything else is handled in external actionscript files. I have a class for a battle which has some battle related methods like attack etc and I also have characters as their own classes which inherit from an interface.

In my user interface there are some buttons and when a battle commences I have an event listener on my attack button which executes the following code each time:

public function attack(attacker:Character, defender:Character):void
    {

        var defenderHp:int;
        var attackPower:int;
        var postAttackHp:int;

        defenderHp = defender.getHP();
        attackPower = attacker.getAttack();

        if (! passiveBlock(defender))
        {
            if (! criticalStrike(attacker))
            {
                trace("defender hp trace: " + (defenderHp - attackPower));
                postAttackHp = (defenderHp - attackPower);
            }
            else
            {
                trace("defender hp trace: " + Math.floor((defenderHp - (attackPower*1.5))));
                postAttackHp = Math.floor((defenderHp - (attackPower*1.5)));
                displayText = attacker.getName() + " landed a critical strike!";
            }

            if (! postAttackHp > 0)
            {
                gameIsOver(attacker, defender);
            }
            else
            {
                defender.setHP(postAttackHp);
            }
        }
        else
        {
            displayText = defender.getName() + " blocked the attack!";
        }

    }

The code gets called by the button fine every time, the problem lies in the if (! postAttackHp > 0) condition. For some reason only occasionally does the game over method get called when the defender’s HP goes below 0. I am tracing the postAttackHp variable out each time and I can see every time that it is below 0 but the if statement more often than not skips down to the else section.

What is strange is that sometimes it works properly and sometimes it does not but it is more frequently not working.

Is there something fundamentally stupid about the way this is set up?

Thanks in advance for your help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:14:32+00:00Added an answer on June 5, 2026 at 12:14 am

    I don’t have Flash installed on this machine, or else I would try to see if this is the issue, but my first guess would be that

    ! postAttackHp > 0
    

    is evaluating as (! postAttackHp) > 0. In this case, it would only be true if postAttackHp were == 0. Anything else, even a negative number, would evaluate to False, since ! -10 = False. False > 0 is False, since typecasting False would leave it as 0.

    Try either,

    if (! (postAttackHp > 0))
    

    or

    if (postAttackHp <= 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small game in android that basically is a turn-based boardgame,
I'm writing a small game for Windows Phone 7. It's a vocabulary based game,
A little background: I'm writing a small word based maze game starting with a
I'm writing a small game (with DC), I would like to use some Flash
Inspired by Brent Yorgey's adventure game , I've been writing a small text based
I am writing a small game by using cocos2d. It is a shooting game.
I am writing a small game for Android. The game is drawn on a
I have am writing a small game using Applet. I want to be able
I am currently considering writing a small game. It is essentially a map where
I have writing a small shooting game in cocos2d. Winning the game is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.