Page 27 of 117

Re: Scripters cove

Posted: Thu Jan 13, 2011 8:04 pm
by JensAyton
Eric Walch wrote:
it still makes sense to check for "ship.docked == true
Just check if (ship.docked). Explicitly comparing to true serves no purpose except in specialized situations.

Re: Scripters cove

Posted: Tue Mar 01, 2011 3:45 pm
by CaptSolo
Could someone please tell me the Oolite coordinate system as it pertains to the view screen? Thanks

Re: Scripters cove

Posted: Tue Mar 01, 2011 7:31 pm
by Svengali
CaptSolo wrote:
Could someone please tell me the Oolite coordinate system as it pertains to the view screen? Thanks
If I get this right you are talking about custom_views? If so then
[wiki]Shipdata.plist[/wiki] (custom_views), view_position is X,Y,Z - [0,0,0] should be the center.
[wiki]Quaternion[/wiki]

A good overview about Oolite
http://wiki.alioth.net/index.php/Catego ... _scripting

Re: Scripters cove

Posted: Tue Mar 01, 2011 9:33 pm
by CaptSolo
Svengali wrote:
CaptSolo wrote:
Could someone please tell me the Oolite coordinate system as it pertains to the view screen? Thanks
If I get this right you are talking about custom_views? If so then
[wiki]Shipdata.plist[/wiki] (custom_views), view_position is X,Y,Z - [0,0,0] should be the center.
[wiki]Quaternion[/wiki]

A good overview about Oolite
http://wiki.alioth.net/index.php/Catego ... _scripting
Thanks for your reply. Should have been more specific as I was referring to the Forward, rear, left and right views. But I figured it out by studying the hud.plist. I have made a copy of that file to the Add Ons folder to tinker with.

Re: Scripters cove

Posted: Wed Mar 02, 2011 3:34 am
by CaptSolo
Considering this snippet from hud.plist,

Code: Select all

{	// scanner
	alpha		= 1.0;
	selector	= "drawScanner:";
	x		= 0;
	y		= 60;
	y_origin	= -1;
	height	= 72.0;
	width		= 288.0;
	rgb_color	= (1.0, 0.0, 0.0);
},
Made me ask two questions:
1) How is this procedure executed / handled?
2) How many draw procedures are there other than drawing rectangles, circles, and ellipses that a scripter could use?

Re: Scripters cove

Posted: Sun Mar 06, 2011 1:34 pm
by Okti
Hi,

Is there a way to call a function in a world script from another one.

Like a callback passed by a string.

As an example

Word Script A
this.startUp = function()
{
this.callback="B";
}
this.B = function(option)
{
log(this.name,option);
}


And second script can retrieve the name of the call back by worldScripts("A").callback;

But I could not achieve to call the callback from second script.

Re: Scripters cove

Posted: Sun Mar 06, 2011 1:43 pm
by Commander McLane
You can call any world script function from any other script by pre-fixing the world script name.

Example: this.$setUpSystem() in the Anarchies-script can be called from anywhere (including the JS-console, which is particularly useful for playtesting) with worldScripts.Anarchies.$setUpSystem().

The prefix for world scripts is worldScript (see here), which is followed by the script name (the one specified in this.name at the top of your world script). There are some special rules if your script name contains a SPACE.

Re: Scripters cove

Posted: Sun Mar 06, 2011 1:51 pm
by Okti
Thanks Commander McLane,

But my problem is trying to pass the name of the function as a string property.

wordScripts("MyWordScript") gets my MyWordScript. Like this I want to call a Function in that world script by name.

Re: Scripters cove

Posted: Sun Mar 06, 2011 3:04 pm
by Okti
Never mind I solved the problem.

Re: Scripters cove

Posted: Sun Mar 06, 2011 3:18 pm
by DaddyHoggy
If you say how, others will benefit from your discovery...

Re: Scripters cove

Posted: Sun Mar 06, 2011 3:24 pm
by Okti
DaddyHoggy wrote:
If you say how, others will benefit from your discovery...
You are right.

The method is

Code: Select all

worldScripts["scriptname"]["functionname"](args);
I tried it at the first place but I forgot to add this. before the function name :D

Re: Scripters cove

Posted: Sat Apr 09, 2011 4:19 am
by Capt. Murphy
Morning (yawn),

Anyone know if the variable ship_trade_in_factor in the save file is visible to JS and if so what's the property to access it (player.ship.something???).

Ta,

Re: Scripters cove

Posted: Sat Apr 09, 2011 9:57 am
by Eric Walch
Okti wrote:
The method is

Code: Select all

worldScripts["scriptname"]["functionname"](args);
I tried it at the first place but I forgot to add this. before the function name :D
That you need to include "this." when writing it down as string is new to me. I always used:

Code: Select all

worldScripts.scriptname.functionname(args)
for calling functions with parameters in other scripts. Or

Code: Select all

worldScripts["scriptname"].functionname(args)
Both go without a "this". Writing down as string is only needed when the string contains special characters. A scriptname might contain such characters, but a function never.
"Capt Murphy"]Anyone know if the variable ship_trade_in_factor in the save file is visible to JS and if so what's the property to access it (player.ship.something???).
ship_trade_in_factor is not exposed.

Re: Scripters cove

Posted: Sat Apr 09, 2011 11:20 am
by JensAyton
Eric Walch wrote:
Both go without a "this". Writing down as string is only needed when the string contains special characters. A scriptname might contain such characters, but a function never.
foo.bar is purely shorthand for foo["bar"]. There is no difference in behaviour. As such, foo["Fred Bloggs"] = function () {} is perfectly valid.

Re: Scripters cove

Posted: Sat Apr 09, 2011 12:19 pm
by Thargoid
But foo.fred bloggs = function() isn't due to the space (an example of the special characters).

Personally I always tend to use worldScripts["name"] rather than worldScripts.name even when name doesn't include a space or somesuch, just for consistency. But as Eric says, the functions themselves never will have such characters in them by definition.