A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: A Button Script Won't Work Right (AS2)

  1. #1
    Junior Member
    Join Date
    Aug 2015
    Posts
    26

    A Button Script Won't Work Right (AS2)

    Hi everyone I'm here because Idk what else to do, I had it up to here with this script. XD I know a bit of Actionscript 2 and I can have buttons and random scenes play, however having a button that "plays" a random scene is what I need help with. Let me be a bit clear on what I'm trying to do, I'm working on a flash animation with a turn based battle system. I can do those no problem as seen here

    http://discourt.deviantart.com/art/D...rn-3-442083645

    but this time I wanted to add scenes where the player "misses", that way it's not too easily and a bit unique. However the script I found just doesn't work, at first it only played the scene where the player lands the hit, but now it won't even show the numbers needed for the miss scene! I have it where you can see the numbers needed for the random script, you know the Dynamic Text thing? I use a script to randomize that for the non playable character's attack so each turn his attack is randomized. I did try to use that for the player attacks too so it would be random between hit or miss, but no go.

    Anyways the new issue is the script just won't show certain numbers, like to test this theory out I set the script to land the attack if the player's Dynamic Text is either 1 or 2 and if it's instead 3-10 to miss, however it kept going between 0-2 never going any higher. So knowing that theory was correct I have no idea what to do anymore, like a month or so trying to get this stupid script to work but even with a friend's help it refuses to work. The script is this btw, keep in mind I use flash 8 and Actionscript 2.

    on (release) {
    function randRange(min, max){
    var randomNum= Math.round(Math.random()*(max-min))+min;
    return randomNum;
    }
    var gatk;
    if (gatk = randRange(1,8)){
    gotoAndPlay("attack");
    }
    else
    {
    var gatk;
    if (gatk = randRange(9, 10)){
    gotoAndPlay("attackmiss");
    }
    }
    }
    If anyone can help me I would be very grateful, I might just end up deleting the miss scenes/frames because if I can't get this script to work I whether not waste more months for nothing. This one script had pushed back this animation far longer than it should've, and it took hours to even find this one!!!! So please someone try and help? ^^; Also if your wondering gatk is short for "good attack".

  2. #2
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    is it somethink like this you are looking for ?



    on (release) {

    randomNum=Math.floor(Math.random() * 10) + 1;
    gatk=randomNum;

    if (gatk >=1 and gatk <=8){
    gotoAndPlay("attack");
    }else{
    if (gatk >=9){
    gotoAndPlay("attackmiss");
    }


    }

  3. #3
    Junior Member
    Join Date
    Aug 2015
    Posts
    26
    That has two errors,

    **Error** Scene=Scene 1, layer=text, frame=6210:Line 1: Statement block must be terminated by '}'
    on (release) {

    **Error** Scene=Scene 1, layer=text, frame=6210:Line 12: Syntax error.
    }

    Total ActionScript Errors: 2 Reported Errors: 2
    but adding a extra } at the end fixes them, testing now. It works. ^^ Thank you I was beginning to think no one was gonna reply. It can get pretty annoying when that script error notice pops up as at times it doesn't explain what exactly you need to fix, at least I could never figure it out as sometimes by fixing 1 error it adds like 3 more. XD

    Happy this works tho, a big weight off my shoulders now thanks. XD
    Last edited by Cody2819; 08-10-2015 at 10:28 AM.

  4. #4
    Junior Member
    Join Date
    Jul 2015
    Posts
    8
    glad you got it to work I did not test it myself

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    PHP Code:
    on (release) {

        var 
    gatk:Number Math.floor(Math.random() * 10) + 1;

        if (
    gatk 8)
        {
            
    gotoAndPlay("attackmiss");
            
    //trace("Miss: " + gatk);
        
    }
        else
        {
            
    gotoAndPlay("attack");
            
    //trace("Attack: " + gatk);
        
    }


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