missing semicolon ?!?

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

missing semicolon ?!?

Post by Zieman »

This is driving me nuts - Oolite (Trunk 1.75.4.4621) keeps complaining about missing semicolons in my script for no apparent reason.

Code: Select all

21:56:53.984 [script.javaScript.exception.semiBeforeStmnt]: ***** JavaScript exception (fa-nova.js.anon-script): SyntaxError: missing ; before statement
21:56:53.984 [script.javaScript.exception.semiBeforeStmnt]:       ../AddOns/Far_Arm_ships_v3.0_beta3.oxp/Scripts/fa-nova.js, line 9: 	this.FANovaECMx = Math.floor(Math.random()*10)+1)*100000;
21:56:53.984 [script.javaScript.load.failed]: ***** Error loading JavaScript script ../AddOns/Far_Arm_ships_v3.0_beta3.oxp/Scripts/fa-nova.js -- compilation failed
21:56:53.984 [script.javaScript.exception.semiBeforeStmnt]: ***** JavaScript exception (fa-nova.js.anon-script): SyntaxError: missing ; before statement
et cetera, et cetera ...

Script in question:

Code: Select all

this.name = "Nova missile ECM script";
this.author = "Zieman";
this.copyright = "CC-by-nc-sa-3.0";
this.description = "Nova missile ECM reaction";
this.version = "3.0";

fanovaecmd = function()
{
	this.FANovaECMx = Math.floor(Math.random()*10)+1)*100000;
	this.FANovaECMy = Math.floor(Math.random()*10)+1)*100000;
	this.FANovaECMz = Math.floor(Math.random()*10)+1)*100000;
	this.ship.reactToAIMessage("setCoordinates: wsm FANovaECMx FANovaECMy FANovaECMz");
};
Line number 9 is:

Code: Select all

	this.FANovaECMx = Math.floor(Math.random()*10)+1)*100000;
If I change the script to be:

Code: Select all

this.name = "Nova missile ECM script";
this.author = "Zieman";
this.copyright = "CC-by-nc-sa-3.0";
this.description = "Nova missile ECM reaction";
this.version = "3.0";

this.shipSpawned = function()
{
	var FANovaECMx = Math.floor(Math.random()*10)+1)*100000;
	var FANovaECMy = Math.floor(Math.random()*10)+1)*100000;
	var FANovaECMz = Math.floor(Math.random()*10)+1)*100000;
};

fanovaecmd = function()
{
	this.ship.reactToAIMessage("setCoordinates: wsm FANovaECMx FANovaECMy FANovaECMz");
};
I still get the same error(s) :(
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: missing semicolon ?!?

Post by Switeck »

Looks like you're closing 1 more ) than you're opening
this.FANovaECMx = Math.floor(Math.random()*10)+1)*100000;
The ) after the +1 has no corresponding ( to go with it.

Perhaps you meant to do this instead?:
this.FANovaECMx = Math.floor(Math.random()*10+1)*100000;
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: missing semicolon ?!?

Post by Zieman »

Well spotted, thanks!

Actually, I want

Code: Select all

this.FANovaECMx = (Math.floor(Math.random()*10)+1)*100000;
Let's see if fixing that changes anything...
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: missing semicolon ?!?

Post by Zieman »

Oh yeah, fixing parentheses made semicolon-errors go away... :roll:
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: missing semicolon ?!?

Post by Thargoid »

You also don't need the semi-colons at the end of the functions (after the } that closes them)
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: missing semicolon ?!?

Post by Zieman »

Ah, ok.

Now if I could just get the AI to actually receive (and act on) the variables' values...
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: missing semicolon ?!?

Post by Eric Walch »

Zieman wrote:
Ah, ok.

Now if I could just get the AI to actually receive (and act on) the variables' values...
The line:

Code: Select all

this.ship.reactToAIMessage("setCoordinates: wsm FANovaECMx FANovaECMy FANovaECMz");
Will send the whole message and tries to use it as message key. You can't transfer coordinates that way. With AI alone you can only set hardcoded coordinates.

On the positive side: you can use:

Code: Select all

this.ship.savedCoordinates = Vector3D(FANovaECMx, FANovaECMy, FANovaECMz).toCoordinateSystem("wsm")
You don't need the AI to set coordinates.

You also are advised to precede all functions you define at the bottom level with 'this' to make them local to the script. If you don't do that, they will be globally defined and shared between all Oolite scripts. If the name is not unique enough, you risk conflicts with other oxps using similar names.
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: missing semicolon ?!?

Post by Zieman »

Ok, thanks!
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: missing semicolon ?!?

Post by Eric Walch »

Zieman wrote:
Ok, thanks!
I think in your case it should be "fromCoordinateSystem" not "toCoordinateSystem" as I used above. See fromCoordinateSystem
User avatar
Zieman
---- E L I T E ----
---- E L I T E ----
Posts: 680
Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe

Re: missing semicolon ?!?

Post by Zieman »

Eric Walch wrote:
Zieman wrote:
Ok, thanks!
I think in your case it should be "fromCoordinateSystem" not "toCoordinateSystem" as I used above. See fromCoordinateSystem
Yeah, noticed that when looked for info about savedCoordinates & Vector in the Wiki.

I Decided to drop the .to/fromCoordinateSystem -part, so the script use absolute coordinate system everywhere.

And now I get the results I wanted to get, thanks again :).
...and keep it under lightspeed!

Friendliest Meteor Police that side of Riedquat

[EliteWiki] Far Arm ships
[EliteWiki] Z-ships
[EliteWiki] Baakili Far Trader
[EliteWiki] Tin of SPAM
Post Reply