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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:59:24+00:00 2026-05-27T05:59:24+00:00

I hate that I have to ask a homework question on here, but I

  • 0

I hate that I have to ask a homework question on here, but I can’t help it. I’m taking an ActionScript class in school, and it’s my first time learning a programming language so I feel rather noobish.

The problem was to make an RPG game to practice while loops.

        var fighter1:String = "Wonder Woman";
        var fighter2:String = "Ms. Marvel";
        var health1:uint = 300;
        var health2:uint = 180;
        var damage1:uint = 30;
        var damage2:uint = 40;


        while (health1 >= 0 && health2 >= 0 ) 
        {
            var damageDealt1:uint = Math.random() * damage1;
            var damageDealt2:uint = Math.random() * damage2;
            var attack1:uint = health2 - damageDealt1;
            var attack2:uint = health1 - damageDealt2;
            health1 = attack2;
            health2 = attack1;
            trace("After attack: " + fighter1 + " HP: " + health1 + ", " + 
            fighter2 + " HP: " + health2);
        }
        if (health1==0&&health2==0){
            trace("They both died in battle!  There will now be WAR!");
        } else if (health1==0) {
            trace(fighter2 + " won!");
        } else {
            trace(fighter1 + " won!"
        }

As you can probably tell, damage1 is the potential damage for fighter1, and damageDealt1 is the damage dealt per attack.

Everything seems to work normally except that when I run it I get this:

After attack: Wonder Woman HP: 4280752046, Ms. Marvel HP: 4284398685
After attack: Wonder Woman HP: 4280752039, Ms. Marvel HP: 4284398660
After attack: Wonder Woman HP: 4280752024, Ms. Marvel HP: 4284398658
After attack: Wonder Woman HP: 4280752018, Ms. Marvel HP: 4284398639
After attack: Wonder Woman HP: 4280751997, Ms. Marvel HP: 4284398638
After attack: Wonder Woman HP: 4280751996, Ms. Marvel HP: 4284398612
After attack: Wonder Woman HP: 4280751994, Ms. Marvel HP: 4284398609

ad infinitum…

I’ve translated it to php and it works fine, I just can’t figure out what I’m doing wrong here.

Any ideas? Thanks in advance.

  • 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-05-27T05:59:25+00:00Added an answer on May 27, 2026 at 5:59 am

    as turbosqel said – you have to use int instead of uint:

    var fighter1:String = "Wonder Woman";
    var fighter2:String = "Ms. Marvel";
    var health1:int = 300;
    var health2:int = 180;
    var damage1:uint = 30;
    var damage2:uint = 40;
    
    
        while (health1 > 0 && health2 > 0 ) 
        {
            var damageDealt1:uint = Math.random() * damage1;
            var damageDealt2:uint = Math.random() * damage2;
            var attack1:uint = health2 - damageDealt1;
            var attack2:uint = health1 - damageDealt2;
            health1 = attack2;
            health2 = attack1;
    
            if (health1 < 0) health1 = 0;
            if (health2 < 0) health2 = 0;
    
            trace("After attack: " + fighter1 + " HP: " + health1 + ", " + 
            fighter2 + " HP: " + health2);
        }
    
        if (health1==0&&health2==0){
            trace("They both died in battle!  There will now be WAR!");
        } else if (health1==0) {
            trace(fighter2 + " won!");
        } else {
            trace(fighter1 + " won!"
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hate to have to ask, but I'm pretty stuck here. I need to
I hate to ask this here, but many people on stackoverflow have talked about
I know you guys hate helping with homework, but I thought I might ask
I hate to ask but I had to. I have an html code. For
Visual studio is ok, but i really hate the fact that you have to
I know you are gonna hate me for that kind of question. But could
I hate to ask this question as I am aware that there are plenty
Let me first say that I have quite a lot of Java experience, but
I have to confess that I hate membership provider. The default implementation is not
I have a small to medium project that is in C++/CLI. I really hate

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.