For test results, bug reports, announcements of new builds etc.
Moderators: winston , another_commander , Getafix
Zieman
---- E L I T E ----
Posts: 680 Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe
Post
by Zieman » Sat Nov 05, 2011 8:13 pm
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)
Switeck
---- E L I T E ----
Posts: 2411 Joined: Mon May 31, 2010 11:11 pm
Post
by Switeck » Sat Nov 05, 2011 8:15 pm
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;
Zieman
---- E L I T E ----
Posts: 680 Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe
Post
by Zieman » Sat Nov 05, 2011 8:21 pm
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...
Zieman
---- E L I T E ----
Posts: 680 Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe
Post
by Zieman » Sat Nov 05, 2011 8:40 pm
Oh yeah, fixing parentheses made semicolon-errors go away...
Thargoid
Thargoid
Posts: 5528 Joined: Thu Jun 12, 2008 6:55 pm
Post
by Thargoid » Sat Nov 05, 2011 8:40 pm
You also don't need the semi-colons at the end of the functions (after the } that closes them)
Zieman
---- E L I T E ----
Posts: 680 Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe
Post
by Zieman » Sat Nov 05, 2011 8:42 pm
Ah, ok.
Now if I could just get the AI to actually receive (and act on) the variables' values...
Eric Walch
Slightly Grand Rear Admiral
Posts: 5536 Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands
Post
by Eric Walch » Sat Nov 05, 2011 9:14 pm
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.
Zieman
---- E L I T E ----
Posts: 680 Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe
Post
by Zieman » Sat Nov 05, 2011 9:31 pm
Ok, thanks!
Eric Walch
Slightly Grand Rear Admiral
Posts: 5536 Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands
Post
by Eric Walch » Sat Nov 05, 2011 9:41 pm
I think in your case it should be "fromCoordinateSystem" not "toCoordinateSystem" as I used above. See
fromCoordinateSystem
Zieman
---- E L I T E ----
Posts: 680 Joined: Tue Sep 01, 2009 11:55 pm
Location: in maZe
Post
by Zieman » Sat Nov 05, 2011 10:24 pm
Eric Walch wrote:
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/from CoordinateSystem -part, so the script use absolute coordinate system everywhere.
And now I get the results I wanted to get, thanks again
.