Jump to content

Recommended Posts

Posted

I am having trouble with my code, the code is:

 

{

var num1:Number = 0.5;

if(num < num1)

mc_enemy.y += 20

num = Math.random()

else mc_enemy.y -= 20

num = Math.random()

}

 

And it shows the error, "Error 1083: Syntax error: else is unexpected", Does anybody have any suggestions?

Posted

Indeed. Your if() has two lines after it, but no braces, so only the first line is considered to be inside the if(). Then, a couple of lines later, the parser sees an else, but the if() has already ended. You need to do this:

 

{
var num1:Number = 0.5;
if(num < num1)
{
   	mc_enemy.y += 20
   	num = Math.random()
} else { 
   	mc_enemy.y -= 20
   	num = Math.random()
}
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.