Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 6 of 6

Thread: AS Help

  1. #1
    113
    posts
    Game-Designer in Training

    AS Help

    I posted a thread about this earlier, but I've lost it .
    Anyway, I'm working on a turn-by-turn combat system wherein you click a button to Attack, and it subtracts an amount (your damage) from the enemy's Health (foe). Now, it's easy enough to say:

    on (release) {
    if (damage == 1) {
    foe -= 1;
    }
    if (damage == 2) {
    foe -= 2;
    }
    }
    etc. etc.

    But that's really inefficient, especially considering how many such stats I may be referencing at some point. What I want to know is how to make the script refer to "damage" no matter what the value of it is. If you could provide an example (using "foe and "damage"), that would be great. Also, can you string multiple ones together? (ie. "foe -= (damage + 5)" or "foe -= (damage - defense)")

    Thanks
    Last edited by JapanMan; August 3rd, 2008 at 10:06 PM.

  2. #2
    There's a few ways to do it, but regardless, you ought to get comfortable with writing functions that accept a few parameters. use this as a model.

    Code:
    attacker = { damage:1 };
    foe = { health:5 };
    
    function attack ( damageDealt, opponent )
    {
       opponent.health -= damageDealt;
    }
    
    
    attackButton.onRelease= function ()
    {
        attack( attacker.damage, foe );
    }
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  3. #3
    113
    posts
    Game-Designer in Training
    Quote Originally Posted by therobot View Post
    There's a few ways to do it, but regardless, you ought to get comfortable with writing functions that accept a few parameters. use this as a model.

    Code:
    attacker = { damage:1 };
    foe = { health:5 };
    
    function attack ( damageDealt, opponent )
    {
       opponent.health -= damageDealt;
    }
    
    
    attackButton.onRelease= function ()
    {
        attack( attacker.damage, foe );
    }
    In the above model, wouldn't the foe and damage get set to 5 and 1, instead of referenced, no matter the value? Also, I realize that "attacker" is just a label for the damage value, but shouldn't
    Code:
    opponent.health -= damageDealt
    be "foe.health"?

    I'm probably wrong, I'm a newb, I know...

  4. #4
    Quote Originally Posted by JapanMan View Post
    In the above model, wouldn't the foe and damage get set to 5 and 1, instead of referenced, no matter the value? Also, I realize that "attacker" is just a label for the damage value, but shouldn't
    Code:
    opponent.health -= damageDealt
    be "foe.health"?

    I'm probably wrong, I'm a newb, I know...
    Code:
    // What i have done is create two different objects - attacker and foe.
    // attacker has a property called damage which equals one. here.
    attacker = { damage:1 };
    // foe has a propery called health which equals five here.
    foe = { health:5 };
    
    // this function receives two values: damageDealt, and opponent
    // when you call this function, you substitute damageDealt and opponent
    // with two other values.
    function attack ( damageDealt, opponent )
    {
       opponent.health -= damageDealt;
    }
    
    // lets work with this function.
    // first, let's trace our inital values.
    trace( attacker.damage ); // traces 1...
    trace( foe.health ); // traces 5...
    
    // now let's call the function once.  
    // What this will calculate is foe.health = foe.health - attacker.damage
    attack( attacker.damage, foe );
    
    // and let's trace our object's again..
    trace ( attacker.damage); // traces 1...
    trace( foe.health ); // traces 4...
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  5. #5
    113
    posts
    Game-Designer in Training
    so, if I were to put the code you gave into my game as is, it would work immediately?

  6. #6
    Quote Originally Posted by JapanMan View Post
    so, if I were to put the code you gave into my game as is, it would work immediately?
    Yes, create a new flash movie, and paste it into the timeline on the first frame. Test the movie out.

    Trace statements ( trace( "trace this" ) ) will take what you put in the parentheses and display it in the output window when you test your movie. Get a feel for it, it will save yr (flash) life.
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

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