Clock Crew

Community => Flash & Flash Accessories => Topic farted by: Bong Clock on February 26, 2010, 06:26:08 PM

Title: AS issues
Post by: Bong Clock on February 26, 2010, 06:26:08 PM
So I'm trying to make sort of a guitar hero-esque minigame within a larger game I'm making.
currently there's 4 arrows that when loaded rotate a random direction. Then you have to press the corresponding direction whilst a pointer is colliding with them. the collision and pressing works and the rotation works. the problem is when they're together all the arrows point down.

actually while experimenting right this second i've discovered that even without any roation commands the arrows point themselves down.

onClipEvent (load) {
this._rotation = Math.round(random(4))*90;
}

onClipEvent (enterFrame) {
if (this._rotation=0) {
if (this.hitTest("_root.point") && Key.isDown(Key.LEFT)) {
this._alpha = 0;
}
}
if (this._rotation=90) {
if (this.hitTest("_root.point") && Key.isDown(Key.UP)) {
this._alpha = 0;
}
}
if (this._rotation=180) {
if (this.hitTest("_root.point") && Key.isDown(Key.RIGHT)) {
this._alpha = 0;
}
}
if (this._rotation=270) {
if (this.hitTest("_root.point") && Key.isDown(Key.DOWN)) {
this._alpha = 0;
}
}
}

this code is on each arrow to be rotated and collided with. with the exception of the pointer moving to the right it's the only AS in the whole movie.
Title: AS issues
Post by: Bong Clock on February 26, 2010, 06:32:26 PM
what might be even more helpful is if someone knows a simpler way to do it.
Title: AS issues
Post by: AmberArachnidClock on February 26, 2010, 07:08:59 PM
dont use Math.round() just use round() pretty sure that works
Title: AS issues
Post by: Bong Clock on February 26, 2010, 08:23:14 PM
Quote from: Satellite Clock;1734357dont use Math.round() just use round() pretty sure that works

you win the day. thanks.

EDIT: never mind it didn't work. fuck you.
Title: AS issues
Post by: Bong Clock on February 26, 2010, 08:47:37 PM
so the problem was that by using "=" in my if statements I was actually issuing a  command to make the LEFT side of the = equal to the RIGHT side. replacing the appropriate "=" with "==" fixed the always pointing down problem. now however they aren't rotating at all.
I've even tried moving the rotation command to the frame in the movieclip and giving each of the arrows their own reference name.
a._rotation = math.round(random(4))*90;
b._rotation = math.round(random(4))*90;
c._rotation = math.round(random(4))*90;
d._rotation = math.round(random(4))*90;

so why could this suddenly stop working?
Title: AS issues
Post by: Bong Clock on February 26, 2010, 08:55:10 PM
ok I've fixed it. at the time my internet wasn't working and I wasn't sure if random() returned integer values. so I erred on the side of caution and used the math.round(). The solution was to drop it. Though it works i'm not sure exactly why math.round() made everything break.
onClipEvent (load) {
this._rotation = random(3)*90;
}
onClipEvent (enterFrame) {
if (this._rotation == 0) {
if (this.hitTest("_root.point") && Key.isDown(Key.LEFT)) {
this._alpha = 0;
}
}
if (this._rotation == 90) {
if (this.hitTest("_root.point") && Key.isDown(Key.UP)) {
this._alpha = 0;
}
}
if (this._rotation == 180) {
if (this.hitTest("_root.point") && Key.isDown(Key.RIGHT)) {
this._alpha = 0;
}
}
if (this._rotation == 270) {
if (this.hitTest("_root.point") && Key.isDown(Key.DOWN)) {
this._alpha = 0;
}
}
}

here's the final code. it's completely self contained and can be simply copy/pasted into any movieclip I want to use
Title: AS issues
Post by: RenegadeClock on February 26, 2010, 09:37:19 PM
Doesn't the M have to be capital in Math.round() ?
Title: AS issues
Post by: Bong Clock on February 27, 2010, 10:53:17 PM
Quote from: RenegadeClock;1734435Doesn't the M have to be capital in Math.round() ?

yes, yes it does. mystery solved.