A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Variable stop at 0???

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    17

    Variable stop at 0???

    Ok, in the frame i have var Number = 100;
    and i have a button that says on (release) { Number -= 10;}.
    I also have a dynamic texbox with the variable Number.
    Now when i try it it takes -10 of the 100 that is in the box... BUt how do i do so it stops at 0?
    So when you come to zero you can click more? Please tell me

  2. #2
    Senior Member
    Join Date
    Oct 2008
    Posts
    227
    Code:
    on(release){
    if(number <= 0){ // If lower than or equal to
    number -= 10;
    } else { // If not
    this.enabled = false; // Disables this button
    }
    }
    There's also
    >= // Higher than or equal to
    != // Not equal to
    == // Equal to
    Last edited by Vexy; 06-07-2010 at 02:59 PM.

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    17

    Nope.

    I putted that in the button and it didnt work
    Strange :/

  4. #4
    Senior Member
    Join Date
    Aug 2009
    Location
    Scotland & England
    Posts
    117
    Vexy got the pointy thing the wrong way round should be higher than without the equals sign.

    if(number > 0)

  5. #5
    Junior Member
    Join Date
    Jun 2010
    Posts
    17

    :o

    Isnt it any other way? Cuz that wont work for me eather. i putted that into the button but, ye, just errors in teh output

  6. #6
    Senior Member
    Join Date
    Aug 2009
    Location
    Scotland & England
    Posts
    117
    Should work, post your code of what you are applying it in and I'll help.

  7. #7
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    Quote Originally Posted by Carr77 View Post
    Ok, in the frame i have var Number = 100;
    and i have a button that says on (release) { Number -= 10;}.
    I also have a dynamic texbox with the variable Number.
    Now when i try it it takes -10 of the 100 that is in the box... BUt how do i do so it stops at 0?
    So when you come to zero you can click more? Please tell me
    Number is a reserved class, I would say choose something different, here is an example:



    Actionscript Code:
    onClipEvent(load){
        var N:Number = 100;
    }

    on(press){
        if(N-10>0){
            N -= 10;
        }else{
            N = 0;
        }
        trace(N);
            //or textfield.text = String(N);
    }


    Also I always always always check BEFORE doing anything... keep this in mind and you will thank me someday!



    Hope this helps!!
    -GK>'.'<

  8. #8
    Junior Member
    Join Date
    Jun 2010
    Posts
    17
    NICE!
    That worked! Sooo thinks
    But it buged out when i put this code in the button:
    on (release) { builders -= 25; money +=35; totalcitizen -= 25; food +=10;}
    if(builders-10>0){
    builders -= 10;
    }else{
    builders = 0;
    }
    trace(builders);
    }

    Whats wrong now :/
    Iv tried to post you code in diffrent places in this code but didnt work ((

  9. #9
    Senior Member
    Join Date
    Aug 2009
    Location
    Scotland & England
    Posts
    117
    You really need to look into syntax structures and learn what { } and ( ) mean.

    Look at your code.

    on (release) { builders -= 25; money +=35; totalcitizen -= 25; food +=10;}
    You open the on release with {... you do some code and then you close your on release with }.

    This means everything else you have written is outside your on(release) statement.

    on (release) {
    builders -= 25; money +=35; totalcitizen -= 25; food +=10;
    if(builders-10>0){
    builders -= 10;
    }else{
    builders = 0;
    }
    trace(builders);
    }

    Don't just guess where code should go, understand and use it.

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