I've uploaded a simple expansion pack here: http://wiki.alioth.net/index.php/Scanne ... nhancement . Sorry, no corresponding wiki page yet as the missus is telling me to get off the computer! It needs Oolite version 1.81 or better.
When purchased (at, I think, TL12 and above), it makes new "yellow lollipops" on your scanner flash yellow/brown, and it console-logs the class of ship that's just appeared on the scanner. It's supposed to be mildly helpful in the event of a crowded playing field. It may just be irritating -- you tell me.
I'd be grateful for any comments you may have. One in particular from me: should this be primable?
Thanks.
Last edited by jh145 on Sat May 16, 2015 10:27 am, edited 1 time in total.
var pss = player.ship.script;
pss.shipTargetAcquired = function(target) {
More simple if you define a this.shipTargetAcquired function in any worldScript which will be called for the player only. All ship script event handlers are usable for the player in worldScripts.
var targets = system.filteredEntities(this,this._entityToWatch,player.ship,25600);
for (var i=0; i<targets.length; i++) this._updateScannerDisplayColour(targets[i],this._IN_RANGE);
A much faster way can prevent momentary stops in every seconds in slow machines:
How do I define a worldScript which will be called for the player only? Or can I just define this.shipTargetAcquired in the single worldScript that I currently have?
How do I define a worldScript which will be called for the player only?
Any ship script event handler can be used on a world script and applies to the player ship only in that case. This also keeps your player ship script events separated from everyone else's.
The only time I think you'd be better to define events on the player ship script were if they were specific to the ship hull type of the player, and in that case you'd be best predefining them by attaching the ship script in shipdata.plist
Norby wrote:
Even you can define the equipment activated and mode functions here also if you like to see your whole code in a single editor window.
You can do that, but I wouldn't recommend it, because the two functions will get called in different contexts to the rest of the script, so code like this will mysteriously fail
because this.$equipmentStatus in the equipment script and this.$equipmentStatus in the world script are separate variables existing in separate running copies of the script source.
Having the code in two windows is a good thing, as it reminds you that they're separate scripts.
Are those two functions called by the core game only when the keys are pressed? I mean, there's no "deactivate" function called when another piece of equipment gets primed, or anything like that, is there?
Are those two functions called by the core game only when the keys are pressed? I mean, there's no "deactivate" function called when another piece of equipment gets primed, or anything like that, is there?
No, there are just the two functions bound to key presses. That's all.
Any ship script event handler can be used on a world script and applies to the player ship only in that case. This also keeps your player ship script events separated from everyone else's.
Frustratingly, that's harder to get right than I expected.
this.shipTargetAcquired = this._SAE_rememberOne; // doesn't work
this.shipTargetAcquired = function(target) { this._SAE_rememberOne(target); } // works fine
What javascript context nonsense am I not understanding here?
this.shipTargetAcquired = this._SAE_rememberOne; // doesn't work
this.shipTargetAcquired = function(target) { this._SAE_rememberOne(target); } // works fine
The only reason I could think of that those would give different results is if this._SAE_rememberOne isn't defined until after this.shipTargetAcquired - in that situation, the first case would set it to undefined when the script was first loaded, and never touch its value again; the second wouldn't check the value of this._SAE_rememberOne until the handler was actually called, by which time it would have been defined.
If this._SAE_rememberOne is being defined above that line, then no idea - I'd need to look at the whole script.