Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2487
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Phasted wrote: Fri Jan 31, 2025 7:28 am
Phasted wrote: Tue Jan 21, 2025 8:27 pm
I'd like to avoid tossing any garbage into the global space if it's at all possible...
I'm reluctant to do it, but here's what I'm thinking:

Code: Select all

// ...in the worldScript (outside of any function...)
if(!OXP){var OXP = {};} //  creates an "OXP" object in the global space 
OXP.JEM = {}; // A "JEM" object as a property of "OXP", claiming a chunk of the OXP object for myself (JEM -- my initials).
OXP.JEM.RLE = {};  // An "RLE" object to provide a home for everything "Real-life Economics"-related...
// ... then in the market script (or whatever other script to which I need a reference)
OXP.JEM.RLE.someCleverlyNamedProperty = this;
I can then refer to that script from any other script... as can anyone else from any script in any OXP...

Anybody else who wants a piece of the action can attach their own JEM-equivalent object to "OXP" and have at it!

One little object in the global space isn't really such a big deal, right? :roll:
But that depends on doing stuff from the market script; you asked if you could access market scripts from world scripts, not whether you could access world scripts from market scripts.

You don't need a global object for that, just use a normal world script:-

Code: Select all

worldScripts.marketDefs.RLE.CleverlyNamedProperty = this;
Make Zimbabwe Rhodesia Again. :lol: :shock:
User avatar
Phasted
Competent
Competent
Posts: 54
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted »

Wildeblood wrote: Fri Jan 31, 2025 10:11 am
Phasted wrote: Fri Jan 31, 2025 7:28 am
Phasted wrote: Tue Jan 21, 2025 8:27 pm
I'd like to avoid tossing any garbage into the global space if it's at all possible...

You don't need a global object for that, just use a normal world script:-

Code: Select all

worldScripts.marketDefs.RLE.CleverlyNamedProperty = this;
I can put that line in the market script and then address that market script as:

Code: Select all

worldScripts.marketDefs.RLE.CleverlyNamedProperty
I didn't know worldScripts could be used that way... I thought the only properties of worldScripts were the this.name properties of the loaded world scripts...
Post Reply