A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Random number decrease

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    119

    Random number decrease

    Hey all, i have this script

    on (release) {
    health -= 10;
    if (health>500) {
    health = 500;
    }
    if (health<1) {
    _root.gotoAndPlay("gameover");
    }
    }
    I was wondering if there is a code i can use to replace the 10 with a random number between say 1-10.

    (Ergo when the script triggers the health is decreased with something between 1-10 instead of the set nr 10)

    Thanks!

  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    26
    health -= 1 + random(10)

    random(10) will give a number between 0-9
    Last edited by tigalima; 10-23-2010 at 01:07 PM.

  3. #3
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Actionscript Code:
    health = 5000;
    btn.onRelease = function() {
        if (health>500) {
            health = 500;
        }
        health -= (random(10));
        trace(health);
        if (health<1) {
            trace("gameover");
        }  
    };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center