Rock Hermit Locator add on

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

Moderators: winston, another_commander

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

Re: Rock Hermit Locator add on

Post by Switeck »

No Repair Systems (RepairBots repair system or otherwise) on my ship at this time.

Sometimes the duplicate buoys aren't added until after I dock and relaunch from a station...especially funny if it's a Rock Hermit, since I "see double" after launching.

Part of the problem may be with the way Rock Hermit Locator is coded, in rockHermitLocator.js line 45:

Code: Select all

if (this.buoyTimer) {this.buoyTimer.stop(); delete this.buoyTimer};
This line gets called after buoys are added, but it seems remotely possible for the buoyTimer to trigger again before reaching the shutoff line. Which might explain why I see duplicated buoys but never 3 buoys in 1 spot.
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: Rock Hermit Locator add on

Post by Eric Walch »

Switeck wrote:
Part of the problem may be with the way Rock Hermit Locator is coded, in rockHermitLocator.js line 45:

Code: Select all

if (this.buoyTimer) {this.buoyTimer.stop(); delete this.buoyTimer};
This line gets called after buoys are added, but it seems remotely possible for the buoyTimer to trigger again before reaching the shutoff line. Which might explain why I see duplicated buoys but never 3 buoys in 1 spot.
It should not be possible to be called twice. The only way it could happen is when you launch within 0.9 seconds from a station, after entering a system from witchspace.

[private note]check if entering a system while docked on a carrier works correct[/private note]

Note that the part:

Code: Select all

this.buoyTimer.stop()
is not part of the release version. You probably added it yourself to absolutely make sure the timer is stopped. It won't hurt and ensures the timer is not firing again by an hypothetical oolite bug.

To me it looks more like a double installation of the oxp. You can double check that by adding a log line.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Rock Hermit Locator add on

Post by Switeck »

Eric Walch wrote:
Note that the part:

Code: Select all

this.buoyTimer.stop()
is not part of the release version. You probably added it yourself to absolutely make sure the timer is stopped. It won't hurt and ensures the timer is not firing again by an hypothetical oolite bug.
Perhaps the link here:
http://www.box.com/shared/5e46br3nus
...that I downloaded from has the wrong or corrupted file/s?
Is the release version hosted somewhere else? :?
Eric Walch wrote:
To me it looks more like a double installation of the oxp. You can double check that by adding a log line.
I did better, I added 2 log lines to the this.addBuoys section:

Code: Select all

this.addBuoys = function ()
{ 
	log(this.name,"Adding Buoys!");
    this.buoy = (player.ship.equipmentStatus("EQ_ROCKHERMIT_SCANNER") === "EQUIPMENT_OK") ? "rockbeacon" : "rockbeacof"; 
    function addIfRockHermit(ships, buoy)
    { 
      for (var i = 0; i < ships.length; i++)
      {
         if (ships[i].name === "Rock Hermit")
         {
			log(this.name,"Adding Buoy for: "+ships[i].name+" #: "+i);
            if (0 < oolite.compareVersion("1.75"))
                system.addShips(buoy, 1, ships[i].position.add(ships[i].orientation.vectorForward().multiply(10E3)), 1); 
            else
                system.addShips(buoy, 1, ships[i].position.add(ships[i].vectorForward.multiply(10E3)), 1); 
         } 
      } 
   } 
   addIfRockHermit(system.shipsWithPrimaryRole("rockhermit"), this.buoy); 
   addIfRockHermit(system.shipsWithPrimaryRole("pirate-cove"), this.buoy); 
   this.buoysAdded = true;
   if (this.buoyTimer) {this.buoyTimer.stop(); delete this.buoyTimer};
};
I caught probably how/why duplicate Buoys are being created thanks to the logging.
...A Pirate Cove being added at an odd moment!
But the output from it is downright bizarre:

Code: Select all

13:41:43.937 [rockHermit_Locator]: Adding Buoys!
13:41:43.937 [undefined]: Adding Buoy for: Rock Hermit #: 0
13:41:45.968 [deep_space_pirates]: Adding trader convoy to dangerous system! Total traders 7
13:41:45.984 [deep_space_pirates]: Added Pirate Cove to dangerous system!
13:41:46.859 [rockHermit_Locator]: Adding Buoys!
13:41:46.859 [undefined]: Adding Buoy for: Rock Hermit #: 0
13:41:46.859 [undefined]: Adding Buoy for: Rock Hermit #: 0
this.name changed from rockHermit_Locator to undefined in the span of 8 lines of code. And why is the variable i equal to 0 in all 2(3?) cases?!
User avatar
Tricky
---- E L I T E ----
---- E L I T E ----
Posts: 821
Joined: Sun May 13, 2012 11:12 pm
Location: Bradford, UK. (Anarchic)

Re: Rock Hermit Locator add on

Post by Tricky »

Switeck wrote:
Eric Walch wrote:
Note that the part:

Code: Select all

this.buoyTimer.stop()
is not part of the release version. You probably added it yourself to absolutely make sure the timer is stopped. It won't hurt and ensures the timer is not firing again by an hypothetical oolite bug.
Perhaps the link here:
http://www.box.com/shared/5e46br3nus
...that I downloaded from has the wrong or corrupted file/s?
Is the release version hosted somewhere else? :?
Eric Walch wrote:
To me it looks more like a double installation of the oxp. You can double check that by adding a log line.
I did better, I added 2 log lines to the this.addBuoys section:

Code: Select all

this.addBuoys = function ()
{ 
	log(this.name,"Adding Buoys!");
    this.buoy = (player.ship.equipmentStatus("EQ_ROCKHERMIT_SCANNER") === "EQUIPMENT_OK") ? "rockbeacon" : "rockbeacof"; 
    function addIfRockHermit(ships, buoy)
    { 
      for (var i = 0; i < ships.length; i++)
      {
         if (ships[i].name === "Rock Hermit")
         {
			log(this.name,"Adding Buoy for: "+ships[i].name+" #: "+i);
            if (0 < oolite.compareVersion("1.75"))
                system.addShips(buoy, 1, ships[i].position.add(ships[i].orientation.vectorForward().multiply(10E3)), 1); 
            else
                system.addShips(buoy, 1, ships[i].position.add(ships[i].vectorForward.multiply(10E3)), 1); 
         } 
      } 
   } 
   addIfRockHermit(system.shipsWithPrimaryRole("rockhermit"), this.buoy); 
   addIfRockHermit(system.shipsWithPrimaryRole("pirate-cove"), this.buoy); 
   this.buoysAdded = true;
   if (this.buoyTimer) {this.buoyTimer.stop(); delete this.buoyTimer};
};
I caught probably how/why duplicate Buoys are being created thanks to the logging.
...A Pirate Cove being added at an odd moment!
But the output from it is downright bizarre:

Code: Select all

13:41:43.937 [rockHermit_Locator]: Adding Buoys!
13:41:43.937 [undefined]: Adding Buoy for: Rock Hermit #: 0
13:41:45.968 [deep_space_pirates]: Adding trader convoy to dangerous system! Total traders 7
13:41:45.984 [deep_space_pirates]: Added Pirate Cove to dangerous system!
13:41:46.859 [rockHermit_Locator]: Adding Buoys!
13:41:46.859 [undefined]: Adding Buoy for: Rock Hermit #: 0
13:41:46.859 [undefined]: Adding Buoy for: Rock Hermit #: 0
this.name changed from rockHermit_Locator to undefined in the span of 8 lines of code. And why is the variable i equal to 0 in all 2(3?) cases?!
this.name in the local function won't work since the context/scope has changed. Also I would have used displayName rather than name.

Code: Select all

this.addBuoys = function ()
{ 
	log(this.name,"Adding Buoys!");
    this.buoy = (player.ship.equipmentStatus("EQ_ROCKHERMIT_SCANNER") === "EQUIPMENT_OK") ? "rockbeacon" : "rockbeacof"; 
    function addIfRockHermit(context, ships, buoy)
    { 
      for (var i = 0; i < ships.length; i++)
      {
         if (ships[i].name === "Rock Hermit")
         {
			log(context.name,"Adding Buoy for: "+ships[i].displayName+" #: "+i);
            if (0 < oolite.compareVersion("1.75"))
                system.addShips(buoy, 1, ships[i].position.add(ships[i].orientation.vectorForward().multiply(10E3)), 1); 
            else
                system.addShips(buoy, 1, ships[i].position.add(ships[i].vectorForward.multiply(10E3)), 1); 
         } 
      } 
   } 
   addIfRockHermit(this, system.shipsWithPrimaryRole("rockhermit"), this.buoy); 
   addIfRockHermit(this, system.shipsWithPrimaryRole("pirate-cove"), this.buoy); 
   this.buoysAdded = true;
   if (this.buoyTimer) {this.buoyTimer.stop(); delete this.buoyTimer};
};
As for why is the variable reporting 0 (zero) in all cases, that is because there is only 1 of the hermits of the role type checked for in the system.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Rock Hermit Locator add on

Post by Wildeblood »

Tricky wrote:
Also I would have used displayName rather than name.
I wouldn't, for two reasons: the wiki says if displayName isn't set it will be equal to name, but when I have used it it seems that unless specifically set displayName is undefined; pirate coves have "Rock Hermit" as their displayName anyway, so what would you learn?

I would, however, remove the version check designed to discriminate between Oolite 1.74 and 1.75, which seems out-dated.
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: Rock Hermit Locator add on

Post by Eric Walch »

All the strange things seems explainable. That leaves why the liner are logged twice, 3 seconds apart. That shows that there is no second version of the oxp is active. Does this.shipExitedWitchspace fire twice?

One fix could be to add to the start of the addBuoys funtion:

Code: Select all

    if (this.systemID == system.ID) return; // never fire twice in a system.
    this.systemID = system.ID;
That probably cures the symptoms, but not the reason why the function is called twice.
Sometimes the duplicate buoys aren't added until after I dock and relaunch from a station...especially funny if it's a Rock Hermit, since I "see double" after launching.
Adding on launch should never happen, except on the first launch after loading a game. Somehow I get the feeling there is an other oxp that manipulates this one.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Rock Hermit Locator add on

Post by Commander McLane »

Wildeblood wrote:
Tricky wrote:
Also I would have used displayName rather than name.
I wouldn't, for two reasons: the wiki says if displayName isn't set it will be equal to name, but when I have used it it seems that unless specifically set displayName is undefined;
Right answer, but wrong reasons. this.name in the log refers to the name of the script, not of an entity. Scripts don't have displayNames.

Inside the function addIfRockHermit the this refers to that function. But that function doesn't have a name property, thus this.name becomes undefined.

That's the reason why I always write out the name of the script in the first parameter of the log method. Thus,

Code: Select all

     log("rockHermit_Locator", whatever it is that I want to log);
would be the better code in all cases.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Rock Hermit Locator add on

Post by Wildeblood »

Commander McLane wrote:
Wildeblood wrote:
Tricky wrote:
Also I would have used displayName rather than name.
I wouldn't, for two reasons: the wiki says if displayName isn't set it will be equal to name, but when I have used it it seems that unless specifically set displayName is undefined;
Right answer, but wrong reasons. this.name in the log refers to the name of the script, not of an entity. Scripts don't have displayNames.
:roll: It was this bit that Tricky altered, that I commented on:-
if (ships.name === "Rock Hermit")
{
log(context.name,"Adding Buoy for: "+ships.displayName+" #: "+i);
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Rock Hermit Locator add on

Post by Switeck »

This change should (in theory) avoid duplicate buoys:

Code: Select all

this.addBuoys = function ()
{
	if (this.buoysAdded) return;
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: Rock Hermit Locator add on

Post by Eric Walch »

Not only the duplicate buoys, it will stop any addition after the one on the very first launch. this.buoysAdded is set to true at the first launch and stays true. :) It is only used to handle the special addition after loading a game. After that, buoys only need to be added when arriving from other systems.
Post Reply