PDA

View Full Version : What goes down - does not come up.

flx
10-10-2002, 05:03 PM
Take a look at this (please :))....

onClipEvent (enterFrame) {
if (this._y<=380) {
this._y += 10;
}
if (this._y>=380 and this._x<=530) {
this._x += 10;
}
if (this._X>=530 and this._y>=18) {
this._y -=10;
}
if (this._y<=18 and this._x>=20) {
this._x -= 10;
}
}

Basically I was bored and decided to do a little bit of (simple) scripting. So i thought i'd make a lil blu circle and make it move around the stage.
With this script shown above
- the lil blu circle happily moves down the stage
- then once at the bottom it makes a journey to the right side of the stage.

However, once it has reached the right side it takes one step up and goes no futher.

... WHY?

pom
10-10-2002, 05:57 PM
Hey man,
that's a classic with Flash 5 :) if (this._y<=380) {
this._y += 10;
}
if (this._X>=530 and this._y>=18) {
this._y -=10;
}When your clip has reached the bottom right position, this.y<=380 si false, and this._X>=530 and this._y>=18 is true, so you move up.

Next, both this.y<=380 and this._X>=530 and this._y>=18 are true, so you tell your movie to go up by 10 and down by 10. :D

You can solve that by using another variable (a boolean) to know whether you're going up or down, and another for the left/right motion.

pom :cool:

flx
10-10-2002, 06:16 PM
I was fooled by the one thing i was trying to avoid.. boy i feel :o . :)

Thanx for pointing out my mistake.
Till next time - take care..

flx
10-10-2002, 09:38 PM
I thought I had something here .. but I guess not.

onClipEvent (enterFrame) {
ydir = d;
xdir = r;
}
onClipEvent (enterFrame) {
if (this.ydir == d and this._y<=380) {
this._y += 10;
this.xdir = r;
}
if (this.xdir == r and this._y>=380 and this._x<=530) {
this._x += 10;
this.ydir = u;
}
if (this.ydir == u and this._X>=530 and this._y>=18) {
this._y -= 10;
this.xdir = l;
}
if (this.xdir == l and this._y<=18 and this._x>=20) {
this._x -= 10;
this.ydir = d;
}
}

The same thing as before happens.. but i'm too :cool: to see the conflict. LoL. Well no doubt theres something wrong with my scripting :(.
Are the variables 'ydir' and 'xdir' not being changed?? Who knows..
So, I shall pass my woes on to you.

pom
10-10-2002, 10:29 PM
Well, first thing: put only 1 enterFrame :D I supposed you wanted the first one to be an onLoad, right?

Second thing, why don't you use only one variable? That way you have less tests:onClipEvent (load) {
dir="d";
}
onClipEvent (enterFrame) {
if (dir=="d" and _y<=380) {
_y += 10;
if (_y>=380) dir="r";
}
if (dir=="r" and _x<=530) {
_x += 10;
if (_x>=530) dir="u";
}
if (dir=="u" and _y>=18) {
_y -= 10;
if (_y<=18) dir="l";
}
if (dir=="l" and _x>=20) {
_x -= 10;
if (_x<=20) dir="d";
}
}pom :cool:

flx
10-11-2002, 06:09 PM
Originally posted by pom
[B]Well, first thing: put only 1 enterFrame :D I supposed you wanted the first one to be an onLoad, right?

Well actually.. in my confused logic i thought it would be better to put the variable in an 'enterframe' event - that way it would be updated continuosly. Well thinking about it now i guess you dont have to.

So, does having two 'enterFrame' events mess things up? I just did that to keep it tidy.

*sighs* it's so hard being me and boredom isn't as simple as it used to be :rolleyes:

pom
10-11-2002, 07:02 PM
First rule of the fight club: Never have 2 enterFrames at the same time. Unclear, and unnecessary (you can put everything in one...)

Second rule of the fight club: Well, I don't see why you would need to set the directions to right/down all the time... ;)

pom :)