-
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
-
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.
-
Nope.
I putted that in the button and it didnt work
Strange :/
-
Vexy got the pointy thing the wrong way round should be higher than without the equals sign.
if(number > 0)
-
: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
-
Should work, post your code of what you are applying it in and I'll help.
-
Senior Member
Originally Posted by Carr77
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>'.'<
-
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 ((
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|