Following the discussion in
Thargoids Target Autolock OXP thread:
Ok, got the color stuff working.
OXPConfig defines now an array with 20 elements [ [[c0-color1],[c0-color2]], ... ] and a related missionVariable. A simple example could look like:
Code: Select all
this.startUp = function(){
this.myColor = ["grayColor","greenColor"];
if(worldScripts.OXPConfig) this.grabArrayDelayed = true;
else if(missionVariables.genericUserColors){
var a = JSON.parse(missionVariables.genericUserColors);
this.myColor = a[1];
}
}
this.shipWillLaunchFromStation = function(){
if(this.grabArrayDelayed){
this.myColor = worldScripts.OXPConfig.genericUserColors[1];
delete this.grabArrayDelayed;
}
}
The example defines a default array which is used if neither array, nor the related mV is available. Then it checks if
OXPConfig is installed - if so it delays the access (here shipWillLaunchFromStation) to avoid loading order stuff without the need of a timer and grabs the reference. If a user changes the settings through OXPConfigs GUI the references will be automagically updated as well without any callback/registering or constant checking (associative array). If no
OXPConfig is installed (= array unavailable), it tries to get the data from the mV.
OXPConfig itself does a similiar thing. The default array get defined in the script body. On startUp it tries to read in the mV. If not available the mV gets created. If
OXPConfig shuts down this property is not deleted (unlike most other properties) to stay available for other OXPs. The mV gets updated on leaving the color settings.