Need help debugging ActionScript while loop

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.

Answers


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!"
    }

Need Your Help

Use of unresolved identifier 'UITextBorderStyleRoundedRect' in swift

swift uitextfield sprite-kit skscene

I am trying to create a text field by code in swift, here is snippet of my code:

how to apply validation on dialog form using jquery validation plugin?

jquery cordova jquery-mobile jquery-plugins jquery-validate

i m trying to open a dialog on click of a button and opened dialog contains a login form including username and password and signin button.here is my code of html to open a dialog:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.