News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

AS issues

Farted by Bong Clock, February 26, 2010, 06:26:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bong Clock

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.

Bong Clock

what might be even more helpful is if someone knows a simpler way to do it.

AmberArachnidClock

dont use Math.round() just use round() pretty sure that works

Bong Clock

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.

Bong Clock

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?

Bong Clock

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

RenegadeClock

Doesn't the M have to be capital in Math.round() ?

Bong Clock

Quote from: RenegadeClock;1734435Doesn't the M have to be capital in Math.round() ?

yes, yes it does. mystery solved.