Error in AS

Subscribe to Error in AS 15 posts

avatar for sr2449 sr2449 80 posts
Flag Post

It’s suppose to cause the object the the script is in to move to the top left corner and then back, instead it just goes to the top left corner. I haven’t really used AS in a few years, so I am rusty, anybody see my error?

onClipEvent(load)
{
	rotatespeed = 3;
	timer = 0;
	movedirection = 1;
	movebacktime = 100;
	movespeed = 10
}
onClipEvent(enterFrame)
{
	_rotation += rotatespeed;
	timer += 1;
	if(movedirection = 1)
	{
		_x -= movespeed;
		_y -= movespeed;
	}
	else
	{
		_x += movespeed;
		_y += movespeed;
	}
	if(timer >= movebacktime)
	{
		if(movedirection = 1)
		{
			movedirection = 2;
		}
		else
		{
			movedirection = 1;
		}
		timer = 0;
	}
}
 
avatar for Shake_N_Baker Shake_N_Baker 53 posts
Flag Post

Your if statements are wrong. A single equal sign means assign or set, so if(movedirection = 1) simply sets the movedirection to 1 and continues on as if it were if(true) written there. You want to use two equal signs to compare the value of movedirection and 1 so if(movedirection == 1) would be correct

 
avatar for Khronosis Khronosis 130 posts
Flag Post
Originally posted by sr2449:
if(movedirection = 1)

“=” is for assigning values.
“==” is for comparing values.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post

You realize that you’re telling it to move for 100 frames (in each direction), and each frame to move 10 pixels, right? Which means that it’s entire motion is 1000 pixels.

 
avatar for JWBSoftware JWBSoftware 106 posts
Flag Post

What they wrote about ‘=’ and ‘==’. If you’re using the Flex compiler it will warn you of such things as they’re easy to miss. Or get in the habit of reversing such clauses, i.e. write them like this:

if (1 == movedirection)

Then if you leave out one of the equals signs you have something that’s impossible so which won’t compile.

 
avatar for TJEisemann TJEisemann 25 posts
Flag Post
Originally posted by JWBSoftware:

if (1 == movedirection)

If brown is the cow.

 
avatar for Aesica Aesica 952 posts
Flag Post
Originally posted by TJEisemann:

If brown is the cow.

That’s not how it works. It’d be more like:

if (brown == cow || cow == brown) would always return false, no matter the order because a cow is not a color and a color is not a cow. You’re thinking of:

if (brown == cow.color) which is the same as if (cow.color == brown)

 
avatar for TJEisemann TJEisemann 25 posts
Flag Post

Just commenting on the illogical nature of the logic “if (constant == variable)”.

If the cow is brown.
If brown is the cow.

 
avatar for Ace_Blue Ace_Blue 1093 posts
Flag Post

if (debate.point == null) closeThread(); ?

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by TJEisemann:

Just commenting on the illogical nature of the logic “if (constant == variable)”.

If the cow is brown.
If brown is the cow.

“If brown the cow is” would be more grammatically correct. Brown can’t be a cow.

 
avatar for BigJM BigJM 468 posts
Flag Post
Originally posted by Draco18s:
Originally posted by TJEisemann:

Just commenting on the illogical nature of the logic “if (constant == variable)”.

If the cow is brown.
If brown is the cow.

“If brown the cow is” would be more grammatically correct. Brown can’t be a cow.

You think that’s more grammatically correct? :P

 
avatar for Aesica Aesica 952 posts
Flag Post
Originally posted by BigJM:

You think that’s more grammatically correct? :P

More grammatically correct, it is.

(More logically correct, anyway)

 
avatar for TJEisemann TJEisemann 25 posts
Flag Post
Originally posted by Draco18s:

“If brown the cow is” would be more grammatically correct. Brown can’t be a cow.

Your assuming my cow !== “brown”

 
avatar for JWBSoftware JWBSoftware 106 posts
Flag Post

You don’t have to invoke a green and pointy-eared warrior to justify such an ordering. E.g, considering a lottery win one might say:

“If the winner is me I will give up work”
or
“If I am the winner I will give up work”

Of course “If the winner is I” is more grammatically correct, though people look at you funny if you speak like that. And most people would just say “If I win [the lottery] I will give up work”.

 
avatar for feartehstickman feartehstickman 521 posts
Flag Post
Originally posted by TJEisemann:
Originally posted by Draco18s:

“If brown the cow is” would be more grammatically correct. Brown can’t be a cow.

Your assuming my cow !== “brown”

I believe it’s !=