[F--]"if" statements

ok here is the deal. in my footer, i would like it so that the ball never goes under 1, but that would be a lot of “if” statements to right it :crazy:. so i was wondering what my options would be. this is the current code:


if (speed == 0){
speed = 1;
}
if (speed == .01) {
	speed = 1;
}
if (speed == .02) {
	speed = 1;
}
if (speed == .03) {
	speed = 1;
}
if (speed == .04) {
	speed = 1;
}
if (speed == .05) {
	speed = 1;
}
if (speed == .06) {
	speed = 1;
}
if (speed == .07) {
	speed = 1;
}
if (speed == .08) {
	speed = 1;
}
if (speed == .09) {
	speed = 1;
}
if (speed == .1) {
	speed = 1;
}
if (speed == .2) {
	speed = 1;
}
if (speed == .2) {
	speed = 1;
}
if (speed == .3) {
	speed = 1;
}
if (speed == .4) {
	speed = 1;
}
}

couldnt i use like:


if(speed == speed<1){
                speed = 1;
}

i will try this, but do you think this will work? if not what can i do?

*Originally posted by mdipi.com *
**


couldnt i use like:

if(speed == speed<1){
speed = 1;
}



i will try this, but do you think this will work? if not what can i do? **


you were close.  its just
if(speed&lt;1){
                speed = 1;
}

you can also use

speed = Math.max(speed, 1);

Yes,

if (speed<1) {
speed = 1;
}

Will work…

Math.max??? I think that is something from Flash 4.

Never really used it, To round up you can just do

mySpeed = Math.ceil(speed)

Math.max is Flash 5 or later. Similarly there is Math.min. You can constrain a variable to a range using these:

variable = Math.min(Math.max(MIN, VARIANT), MAX);

for example if you had a clip you wanted to follow its _parent._xmouse but only between _xmouse == 100 and _xmouse == 200 then you can use

this._x = Math.min(Math.max(100, _parent._xmouse), 200);

so they’re nice :wink:

Hrm, learn something new everyday…thanks :slight_smile: