The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 6 of 6

Thread: Some MX Action Script Questions

  1. #1
    113
    posts
    Game-Designer in Training

    Afrostyle Some MX Action Script Questions

    Hello,
    (first post!)

    I'm in the process of making a simple (very simple) RPG, and I had a few questions:
    1. At the moment, all my Damage calculations are controlled by individual "if-statements." For instance:

    on (release) {
    if (damage == 1) {
    enemy-=random(2);
    }
    }

    These statements work fine for now, and are easy to code, but if I assume that a virtually unlimited number of Damage is achievable, I'd rather not have to write thousands of "if's."
    Thus, my question is how to make the coding refer to the value of the Dynamic Text object "damage". Is there something along the lines of:
    on (release) {
    enemy-=random("damage");
    }

    2. I want to have a picture of each enemy by their stats. I was hoping to do this via a Movie Clip with a frame for each picture, and then have the AS tell the MC which frame to go to whenever it generates an enemy. I know this is possible, but I can't seem to get it to work. How should this be done?
    ie.
    if (foe == 1) {
    enemydamage = b;
    enemyname = a;
    **insert coding here**
    }


    Thank you!

  2. #2
    For the first part would this work? (Assuming you have a text field with the instance name as 'damage')

    on(release)
    {
    enemy-=random(parseInt(damage.text));
    }

    This should work so long as damage.text only contains a number.

    As for your second question, I'm a little confused but I guess the way I would do it was to associate an enemyID with each of your enemies, and then for every enemy you have, do a frame in a movieclip displaying each of your enemies. Then when an enemy is generated say with enemyID = 5; I would do displayEnemyClip.gotoAndStop(enemyID);

    I would have thought a nicer way to do this would be to use attachMovie() (in AS2) or addChild() (in AS3)..

  3. #3
    For the first part would this work? (Assuming you have a text field with the instance name as 'damage')

    on(release)
    {
    enemy-=random(parseInt(damage.text));
    }

    This should work so long as damage.text only contains a number.
    I'd do the same but replace
    Code:
    enemy-=random(parseInt(damage.text));
    with
    Code:
    _root.enemy-=int(Math.random()*_root.damage.text);
    AT LEAST ADD _ROOT. BEFORE DAMAGE else it might be really buggy
    Last edited by Lolghurt; June 18th, 2008 at 03:22 AM.

  4. #4
    1,627
    posts
    hugeExplosions = true;
    I'd probably not go with the 'damage' textbox anyway - what's wrong with using a variable? Surely the damage textbox has to get it's value from somewhere - so why not store the value of it in a variable and update the textbox via this variable. Then you don't have to start parsing a textbox to get a number, it just seems like an unneccessary step

    Just remember, you don't need to write lots of if statements when an expression will do.

    Instead of

    Code:
    if(value == 1)  {
      dosomething(1 + 5);
    } 
    else if(value == 2) {
      dosomething(2 + 5);
    }
    else if(value == 3) {
      dosomething(3 + 5);
    }
    You can always use

    Code:
    dosomething(value + 5);
    Last edited by Charleh; June 18th, 2008 at 04:32 AM.
    MS Paint FTW!


  5. #5
    I would use a variables for both the minimun and maximum amount of damage the player can inflict (assuming a range would not always start from 0), thus, you could just apply damage with the following code:

    Code:
    minDamage = <value>;
    maxDamage = <value>;
     
    enemy -= Math.floor(Math.random() * (_root.maxDamage - _root.minDamage + 1)) + _root.minDamage;
    Also, if this damage depends on the weapon, for instance, you could use something like this:

    Code:
    // Declare Weapons Array and WeaponChange Function
    // [<name>, <minDamage>, <maxDamage>]
     
    weaponsArray = [
    ['Dagger', 2, 5],
    ['Sword', 4, 10],
    ['Hammer', 3, 8]
    ];
     
    function changeWeapon(weaponID) {
      _root.weaponName = weaponsArray[weaponID][0];
      _root.minDamage = weaponsArray[weaponID][1];
      _root.minDamage = weaponsArray[weaponID][2];
    }
     
    //Everytime the Player changes the Weapon Equiped
    changeWeapon(weaponID);
     
    //Everytime an enemy is hit
    enemy -= Math.floor(Math.random() * (_root.maxDamage - _root.minDamage + 1)) + _root.minDamage;
    Last edited by bpalermo; June 18th, 2008 at 02:41 PM.
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  6. #6
    113
    posts
    Game-Designer in Training
    Great, I'll test these out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012