Jump to content

AS3 Error 1083: Syntax error: else is unexpected NEED HELP

Featured Replies

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?

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()
}
}

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.