Page 1 of 1

Scanner Alerting Enhancement

Posted: Thu May 14, 2015 7:57 pm
by jh145
Wanted: beta tester :mrgreen:

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.

Re: Scanner Alerting Enhancement

Posted: Thu May 14, 2015 10:06 pm
by Norby
Nice work! Here are my usual tips to be the code even nicer. ;)

Code: Select all

  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.

Code: Select all

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:

Code: Select all

var targets = player.ship.checkScanner(true);
for (var i=0; i<targets.length; i++) 
    if(targets[i].scanClass == 'CLASS_NEUTRAL')
        this._updateScannerDisplayColour(targets[i],this._IN_RANGE);
I also suggest to change the timer delay to 1.37 or similar not round value to desync from other oxp's timers for smoother play.

TL5 is enough imho for a light software upgrade in your scanner.

Re: Scanner Alerting Enhancement

Posted: Thu May 14, 2015 10:36 pm
by jh145
Thanks Norby, good advice. I'll get editing.

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?

Re: Scanner Alerting Enhancement

Posted: Thu May 14, 2015 11:57 pm
by Norby
jh145 wrote:
define this.shipTargetAcquired in the single worldScript that I currently have?
Yes. 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.

Re: Scanner Alerting Enhancement

Posted: Fri May 15, 2015 6:46 am
by cim
jh145 wrote:
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

Code: Select all

this.$equipmentStatus = false;

this.shipWillEnterWitchspace = function() {
  this.$equipmentStatus = false;
}

this.$shipDockedWithStation = function() {
  if (this.$equipmentStatus) {
    // do something
  }
}

this.activated = function() {
  this.$equipmentStatus = true;
}
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.

Re: Scanner Alerting Enhancement

Posted: Fri May 15, 2015 6:53 am
by jh145
Norby wrote:
you can define the equipment activated and mode functions
Where's the equipment activation/mode-change API documented? (I'm sure it's somewhere in the javascript reference ...)

Re: Scanner Alerting Enhancement

Posted: Fri May 15, 2015 12:05 pm
by Norby
cim wrote:
the two functions will get called in different contexts to the rest of the script, so code like this will mysteriously fail
Failed at me first time also, then I learned to use worldScripts.myworldscriptname in eq scripts. ;)
jh145 wrote:
Where's the equipment activation/mode-change API documented?
I made this wiki page just now: Equipment scripts

Re: Scanner Alerting Enhancement

Posted: Fri May 15, 2015 3:27 pm
by jh145
Thanks for the wiki page -- a big help!

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?

Re: Scanner Alerting Enhancement

Posted: Fri May 15, 2015 3:41 pm
by Wildeblood
jh145 wrote:
Thanks for the wiki page -- a big help!

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.

Re: Scanner Alerting Enhancement

Posted: Sun May 17, 2015 7:52 am
by jh145
cim wrote:
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.

Consider:

Code: Select all

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?

Re: Scanner Alerting Enhancement

Posted: Sun May 17, 2015 8:06 am
by cim
jh145 wrote:

Code: Select all

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.

Re: Scanner Alerting Enhancement

Posted: Sun May 17, 2015 8:24 am
by jh145
That's it: the function is defined later in the script. Wow, javascript, what a pain.

Anywaaaayyyy... I've fixed the issue now and finally uploaded the OXZ to oolite.org. The scanner alerting enhancement is available to all :D

Re: Scanner Alerting Enhancement

Posted: Sat Jun 05, 2021 5:26 am
by Josef
Hi everybody,
can anyone give me the information inwhat Techlevel it is possible to buy that equipment and how muchit will cost?
Thank you in advance!

Re: Scanner Alerting Enhancement

Posted: Sat Jun 05, 2021 6:35 am
by phkb
Josef wrote: Sat Jun 05, 2021 5:26 am
can anyone give me the information inwhat Techlevel it is possible to buy that equipment and how muchit will cost?
750cr, TL8+ systems.