Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

problems with variable-assigned ships...

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

Moderators: winston, another_commander, Getafix

Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: problems with variable-assigned ships...

Post by Switeck »

Yes, there was a naming discontinuity between:
worldScripts['nullgates'].nullgate
and
this.name = "NullGate";

So I renamed them both to just use "nullgate", and that clears up most of my confusion.

Seems you can't set or check variables in nonexistent worldScripts. :lol:

Btw, what is the difference between this:
worldScripts['nullgate'].nullgate
and this:
worldScripts["nullgate"].nullgate
...if any.
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: problems with variable-assigned ships...

Post by Capt. Murphy »

Switeck wrote:
worldScripts['nullgate'].nullgate
Invalid syntax - you are looking for string value which is by definition enclosed in "string"

edit - fair enough learn something new and all of that....
Switeck wrote:
worldScripts["nullgate"].nullgate
Valid syntax.
Last edited by Capt. Murphy on Wed Mar 14, 2012 7:58 pm, edited 1 time in total.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: problems with variable-assigned ships...

Post by cim »

Capt. Murphy wrote:
Switeck wrote:
worldScripts['nullgate'].nullgate
Invalid syntax - you are looking for string value which is by definition enclosed in "string"
'string' (in single quotes) also works for defining string values in Javascript. So that should work too.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: problems with variable-assigned ships...

Post by Thargoid »

Indeed, the two are equivalent.

You could also use worldScripts.nullgate.nullgate where the first nullgate is the script name and the second is the function name within it. That method does have the disadvantage though that it can't cope with spaces in the script name.
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: problems with variable-assigned ships...

Post by Eric Walch »

Switeck wrote:
Btw, what is the difference between this:
worldScripts['nullgate'].nullgate
and this:
worldScripts["nullgate"].nullgate
...if any.
It's the same, but you can also have:
worldScripts["nullgate's"].nullgate
but not:
worldScripts['nullgate's'].nullgate

So a ' inside a string of double quotes is accepted as part of the string and not as starting/ending point of a string.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: problems with variable-assigned ships...

Post by Switeck »

Which is probably also why this works:
log(this.name,"worldScripts['nullgate'].nullgate is not null!");
...but this does not:
log(this.name,"worldScripts["nullgate"].nullgate is not null!");
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: problems with variable-assigned ships...

Post by Capt. Murphy »

Switeck wrote:
Which is probably also why this works:
log(this.name,"worldScripts['nullgate'].nullgate is not null!");
...but this does not:
log(this.name,"worldScripts["nullgate"].nullgate is not null!");
Notepad++ should give you a clue when this is going to be a problem. When editing a recognised JS script it automatically greys out the text that is part of a recognised string...

log(this.name,"worldScripts['nullgate'].nullgate is not null!")
log(this.name,"worldScripts["nullgate"].nullgate is not null!")
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
Post Reply