Page 1 of 1

renaming the built-in mission scripts

Posted: Fri Nov 14, 2008 4:39 pm
by Commander McLane
I discovered that JS has a problem with recognizing the hyphen (-) in script names. It just doesn't.

As a result of this it is not possible to interact with any world scripts that contain a hyphen in their name, for instance if you want to check for their existence with

Code: Select all

if(worldScripts.that-particular-script)
{
     do stuff
}
or something else. However

Code: Select all

if(worldScripts.that_particular_script)
{
     do stuff
}
or

Code: Select all

if(worldScripts.thatParticularScript)
{
     do stuff
}
works fine.

This concerns all scripts which have a hyphen in their name property, the most outstanding examples of which are the built-in missions (oolite-cloaking-device, oolite-constrictor-hunt, oolite-nova, oolite-thargoid-plans and oolite-trumbles). So I suggest to rename them, in order not to set a bad example for OXPers, who might just copy what they find in the game.

Re: renaming the built-in mission scripts

Posted: Fri Nov 14, 2008 6:12 pm
by Eric Walch
Commander McLane wrote:
I discovered that JS has a problem with recognizing the hyphen (-) in script names. It just doesn't.

As a result of this it is not possible to interact with any world scripts that contain a hyphen in their name, for instance if you want to check for their existence with

Code: Select all

if(worldScripts.that-particular-script)
{
     do stuff
}
In those instances you need to use:

Code: Select all

if(worldScripts["that-particular-script"])
{
     do stuff
}
Without the point and the text between quotes. That way you can use any text including space symbols.

Posted: Sat Nov 15, 2008 7:51 am
by Commander McLane
Ah! Good to know. :D