A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Turn Based Battle System wont work

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    9

    Turn Based Battle System wont work

    Sup,

    Firstly this is probably a basic mistake

    Basically I am making a Turn Based battle system.
    Each Frame is an attack.
    So for the enemy I did this:

    (in scene Frame)
    attack = Math.round (Math.random ()*2)+0;

    so it would randomly attack

    then I also put in this in an object INSIDE my enemy clip

    onClipEvent(enterFrame){


    onClipEvent(enterFrame){


    if (_root.attack == 1 || _root.attack == 2){
    _root.bad.play();
    }

    if (_root.attack == 0){
    _root.bad.gotoAndPlay(12);
    }

    }



    you see what ive tried to do here havent you?

    why isnt it working? it plays, the random value thing works(used dynamic text box to check this) so what am i missing? (using AS2)

  2. #2
    FLASH C0DER
    Join Date
    Sep 2009
    Posts
    19
    use:
    else{
    between them

    [ Site ] - [ Email ]
    Never trust someone with a large hammer.

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    okay it works to this extent:

    if the first value is 0, it does the right attack for 0. However when the value changes to one or two, it still does the attack for 0.

    if the first value one or two it does the attack for one or two, but if it changes to 0 the attack is still the attack that shud be played for one or two

    i know each time the values change coz i got a dynamic text box telling me so.

    EDIT: I will just use an else condition, seems to make sense
    EDIT: Wont really work at all now
    Last edited by cheeseman62; 09-07-2009 at 03:32 AM.

  4. #4
    FLASH C0DER
    Join Date
    Sep 2009
    Posts
    19
    How come you have 1 and 2 in the same if statement?

    [ Site ] - [ Email ]
    Never trust someone with a large hammer.

  5. #5
    Member
    Join Date
    Oct 2008
    Posts
    37
    try this

    code:

    onClipEvent(enterFrame){
    if (_root.attack == 0){
    _root.bad.gotoAndPlay(12);
    } else {
    _root.bad.play();
    }
    }


  6. #6
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    i did the code...

    it works perfectly:

    wen attack = 1 or 2 the enemy defends.

    wen attack = 0 the enemy attacks.

    the attacks randomly happen like this, most of the time the enemy defends. nice


    however i have a text box telling me attacks value.

    it says: 0 and sometimes the enemy will defend, or indeed attack

    same wen it says either one or two... now i know i might be getting fussy but its worrying coz it might stop me from making more enemies with random attacks as i wont know if the attacks work if their unlikely to happen. such as if attack = 1 to 49 the enemy defends. if it = 50 the enemy attacks.

    if attack in the dynamic text box shows 50 and the enemy still defends i might question if attack really works when it actually does, so what is going wrong in the dynamic text box?

    thanks for all the help so far

  7. #7
    Member
    Join Date
    Oct 2008
    Posts
    37
    I have no idea what you mean.. do you mean even though the value says 0 the enemy does both attack and defend?

  8. #8
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    sorry my wordings bad...

    enemy shud ATTACK wen attack variable = 0;

    however wen the dynamic text box that displays attack variable shows a value of 0 (Despite the code) the enemy EITHER defends or attacks.

    and vise versa for the other two values...

    is it clearer now?

  9. #9
    Member
    Join Date
    Oct 2008
    Posts
    37
    so you mean you never know what its going to do despite the attack variable number

  10. #10
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    guess so

  11. #11
    Member
    Join Date
    Oct 2008
    Posts
    37
    put this on your enemy and get rid of the line
    attack = Math.round (Math.random ()*2)+0;

    code:

    onClipEvent(load){
    attack = random(3);
    }

    onClipEvent(enterFrame){
    _root.textbox.text = attack;
    if (attack == 0){
    _root.bad.gotoAndPlay(12);
    } else {
    _root.bad.play();
    }
    }



    works fine for me

  12. #12
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    oh btw, i hope you know that the code isnt actually placed on the movie clip on stage (wer u right click the movie clip and select actions)

    its all placed, even the text box, in a square clip on 2nd frame of the enemy clip.

    anyway it didnt work but i guess ill hav to live with that, thanks for all the help. if you wanna check out my file and see whats wrong just ask, but anyway its not that big a deal, at least the random attacks work fine
    Last edited by cheeseman62; 09-07-2009 at 11:44 AM.

  13. #13
    Member
    Join Date
    Oct 2008
    Posts
    37
    attach your fla and i'll have a look

  14. #14
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    http://www.box.net/shared/zgtsx0d0be

    thanks for the help

    btw the game looks a bit crappy but this is a test.

  15. #15
    Member
    Join Date
    Oct 2008
    Posts
    37
    its saying 'unexpected file format' when i try to open it.. are you running flash8 or cs3.. if its cs3 you will need to save it as flash8 so i can see it

  16. #16
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    sorry its a cs4 file

  17. #17
    Member
    Join Date
    Oct 2008
    Posts
    37
    any way to make it viewable for flash8?

  18. #18
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    nope, only viewable for cs3, those are the only two options that come up... still im okay with the random attacks

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