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 8239967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:19:39+00:00 2026-06-07T20:19:39+00:00

I am trying to make a game in which a button is clicked, and

  • 0

I am trying to make a game in which a button is clicked, and 45 health points from a healthbar goes down. I have all my coding, and it works well, but I want to make the button so that if health is less than 45, nothing is taken from the health bar. I tried using:

if(health < 45) health = health;

But it did not work out. I have a feeling the solution to this problem is easy, but I just can’t figure it out. Obviously, I am very new at this all, and still find it hard to wrap my head around some concepts. This is my coding:

fortyfivedown_btn.addEventListener(MouseEvent.CLICK, fortyfivedownClick);

    var health:int = 100;

    lifebar.gotoAndStop(101);

    function fortyfivedownClick(event:MouseEvent):void{
        health -= 45;
        if(health < 0) health = 0;
        else if(health > 100) health = 100;

        lifebar.gotoAndStop(health + 1);
    }
  • 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-07T20:19:42+00:00Added an answer on June 7, 2026 at 8:19 pm

    Is there anything wrong with simply doing nothing at all if the health is less than or equal to 45? For example, something like this:

    function fortyfivedownClick(event:MouseEvent):void {
        if (health <= 45) {
            return;
        }
        // Perform action
    }
    

    This will cause the function to exit early if the player doesn’t have enough health.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make an editor for a game which has an event system,
Trying to make simple minesweeper game in python, but have one problem. I have
I have just started trying to make a simple game with XNA 3.1 to
I'm trying to make this 2-player web game application using Spring MVC. I have
I'm trying to make my first game, a console tetris. I have a class
I'm trying to make a small Flash game that has a GUI, which is
i am trying to make some kind of reflex like game for android, which
I am trying to make an OpenGL game which has say 3 stages: Welcome,
i am trying to make a very simple game where i have 7 positions
I'm trying to make a side scrolling background game, in which the scrolling is

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.