renaming the built-in mission scripts

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

renaming the built-in mission scripts

Post 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.
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: renaming the built-in mission scripts

Post 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.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

Ah! Good to know. :D
Post Reply