Page 19 of 118

Posted: Thu Jan 07, 2010 1:11 pm
by PhantorGorth
Kaks wrote:
I think he means

Code: Select all

delete this.startUp;
Kaks you are right but I thought that both ways are identical.

Here is the version using delete instead:

Code: Select all

this.name           = "Oxp_A"; 
this.author         = "Author"; 
this.copyright      = "license"; 
this.description    = "Some Description"; 
this.version        = "1.0 alpha 1"; 

this.startUp = function() 
{

      delete this.startUp; // Must be done straight away to prevent loops. It doesn't stop this function from working. 

      // For handling oxps that are written using this template: 
      if (worldScripts.Oxp_B.startUp) worldScripts.Oxp_B.startUp(); // Calls Oxp_B.startUp as it is required to load before your Oxp_A. 
      // Repeat above for each OXP that this OXP depends on. 

      // For handling old oxps that are NOT written using this template: 
      if (worldScripts.Oxp_Old.startUp) 
      { 
         worldScripts.Oxp_Old.startUp(); // Calls Oxp_Old.startUp as it is required to load before your Oxp_A. 
         delete worldScripts.Oxp_Old.startUp; // You do this as Oxp_Old can't. 
      } 
      // Repeat above for each old OXP that this OXP depends on. 

      // Test for existence of an OXP that isn't required but effects the way this OXP works. 
      if (worldScripts["Oxp_X"]) 
      { 
         this.Oxp_X_Exists = true; 
      } 
      else 
      { 
         this.Oxp_X_Exists = false; 
      } 
      // Repeat above for other similar OXP checks. 

      // Do other stuff here as required 

      log(this.name + " " + this.version +" loaded."); // This goes last so the load messages appear the sensible order. 

} 

// Do other stuff here as required
I also dropped the if (this.startUp) and this.loaded = false as there are obviously redundant.
Kaks wrote:
On restart / reload all scripts are reloaded from scratch, so any deleted this.startUp function will be back there, ready to be deleted again.
That's what I thought.

Posted: Thu Jan 07, 2010 1:23 pm
by JensAyton
PhantorGorth wrote:
1) Oolite loads (if the shift key is pressed during starting) all the javascript scripts into memory. (if you don't press shift this is just loaded from cache instead.)
This isn’t quite true, but it’s also not relevant. The compiled scripts Oolite caches are effectively a processed version of the text in the script file. The cache doesn’t affect script behaviour in any way, so it’s best not to think about it.

Eric is correct in that timers can’t fire between different scripts’ startup timers. Of course, timers are still limited in that they don’t allow for dependency chains.

Posted: Thu Jan 07, 2010 1:38 pm
by PhantorGorth
Ahruman wrote:
This isn’t quite true, but it’s also not relevant. The compiled scripts Oolite caches are effectively a processed version of the text in the script file. The cache doesn’t affect script behaviour in any way, so it’s best not to think about it.
That's useful to know. I wasn't 100% sure of the mechanism. I was mostly concern about it for my suggestion for getting my original dependency mechanism to work for dependencies on old oxps but with the changes that are coming with 1.74 that suggestion is now irrelevant.

I now have a method that works for newly written oxps for pre version 1.74 and a method that works for new and old oxps in 1.74. All I need to do is put them together for oxp that are compatible in both sets of versions. For dependencies on old oxps in pre 1.74 you would have to depend on other methods such as the timer method.
Eric is correct in that timers can’t fire between different scripts’ startup timers. Of course, timers are still limited in that they don’t allow for dependency chains.
That's why I find the method less elegant.

Posted: Sun Feb 14, 2010 9:04 pm
by snork
hej,
list-reading is still new to me and I need help to learn if I understood this correctly/ all wrong. :?

So I wanted a prettier but not uber ship and found me a suitable OXP containing two ships, mostly faithful to the Cobra 3 they are modded from.
Now I only ever see the one of them. Looking into the shipyard.plist I see :shock: ... this
<key>price</key>
<integer>470000</integer>

...

<key>techlevel</key>
<integer>10</integer>
...

<key>chance</key>
<real>0.0001</real>
Now, does this mean, that
- every 10,000th TL>=10 shipyard I visit will offer this ship ? (on average)
or
- every 10,000th ship I see offered at TL>=10 shipyards will be such ship ? So, maybe every ~400th or 500th TL>=10 shipyard ?

Leading to the next question : How many TL>=10 systems are there, at all ? I would think certainly no 10,000, but if my 2nd interpretation idea is correct, then there may actually be 1 or even 2 ships of these available in all Ooniverse ?
wiki wrote:
The difference between the local tech level and the ship’s tech level also factor into this.
Should this raise my hopes ? Significantly, I mean ?

In the end, what this means to me, if I ever find it, expensive as it is, I must buy it. :?

[stubborn-mode] And no, I do not want to"hack" / "cheat". If the author planned it this way - fine. Will only make it more special, should I really ever see it. [/stubborn-mode]

..

Posted: Tue Feb 23, 2010 12:08 pm
by Lestradae
How do I translate the legacy "Spawn *role* *number*" into a java script?

I tried "system.legacy_spawn" as a logical option, but to no avail.

So how to spawn something with a java script?

Help is much appreciated.

Re: ..

Posted: Tue Feb 23, 2010 2:45 pm
by Svengali
Lestradae wrote:
How do I translate the legacy "Spawn *role* *number*" into a java script?

Code: Select all

targetShip.spawn("role",number);
or
targetShip.spawnOne("role");
targetShip has to be a valid Entity. So if you're using it in a ship-script you can simply use this.ship.spawn("role",number);
http://wiki.alioth.net/index.php/Oolite ... ence:_Ship tells you more about it...

Posted: Tue Feb 23, 2010 2:58 pm
by Cmd. Cheyd
1.73.4 Code
Specific Example :

Code: Select all

 system.legacy_addShipsWithinRadius('pirate',Num_Pirates,'abs',player.ship.position,25600);

For Trunk See:

http://wiki.alioth.net/index.php/Oolite ... m#addShips

Posted: Tue Feb 23, 2010 3:42 pm
by Commander McLane
Errmmm, Cheyd, ... nope.

The question was about spawn, not one of the addShips methods.

Posted: Tue Feb 23, 2010 3:53 pm
by Cmd. Cheyd
Guess I"m not understanding, as it doesn't seem that different to me. Then again, I've been studying for a certification for work for a few weeks, am in cram week now, and my brain has turned into tapioca...

Posted: Tue Feb 23, 2010 9:26 pm
by JensAyton
spawn() has a bunch of special semantics. In particular:
  • The generated ships have a random position inside the parent ship’s collision radius, and initially face outwards.
  • The generated ships inherit 85 % of the parent’s temperature.
  • If the parent is a missile and the spawned ship has the is_submunition property set, the spawned ship inherits the parent’s owner and target and is flagged as a missile. (Special case for smarter cluster missiles)
  • Unlike addShip family methods, spawn() does not set up escorts, and does not handle auto-selection of trade routes and witchspace jump effects when it happens near a wormhole.
In short, spawn() is the right thing if bits are falling off or out of a ship, and wrong for everything else.

..

Posted: Wed Feb 24, 2010 10:02 am
by Lestradae
Hmm, after reading all this, I think Cmdr Cheyd's

Code: Select all

system.legacy_addShipsWithinRadius('pirate', Num_Pirates, 'abs', player.ship.position, 25600);
... might be fitting for my purpose, too.

I want a sort-of beacon that spawns when a player ship does a certain action. It should spawn somewhere near the player ship and be able to have a station role (yes it's a workaround for something)

So addShipsWithinRadius should work, too.

Will try that first. Thanks all.

Posted: Wed Feb 24, 2010 8:45 pm
by Thargoid
You may also want to look at ship.ejectItem along similar lines perhaps (depending on what you want to do).

Posted: Thu Feb 25, 2010 6:20 pm
by Eric Walch
=== Power tip for mac users. ===

Working on RH I added some log() instructions to batter catch what was happening. While entering a certain mark system and doing something else I suddenly got the message that my mark was killed by someone else.

Looking in the log I found:

Code: Select all

Mark was killed by: [Station "Coriolis Station" "Coriolis Station" ID: 252 position: (105472, 60671.7, 658999) scanClass: CLASS_STATION status: STATUS_ACTIVE] Because of: scrape damage. Last recorded hit: NPC_ATTACK
Apparently my mark just flew into the main station. Other logs told me he never started a fight so I thought at the inspect() method. I never realised you can use it somewhere else than in the console but when I gave my mark the following script:

Code: Select all

this.shipSpawned = function ()
{
    this.ship.inspect();
}
the inspect window opened magically on entering a system with a mark. Without even seeing the ship I could see by the window it was heading to the station, When entering the station aegis it entered the state to go to the witchpoint. But the coordinates showed it was still heading for the station and again it killed itself by crashing into the station.

inspect() is very nice debugging command to remember for mac users.

Posted: Thu Feb 25, 2010 8:07 pm
by Commander McLane
Eric Walch wrote:
When entering the station aegis it entered the state to go to the witchpoint. But the coordinates showed it was still heading for the station and again it killed itself by crashing into the station.
Seems like an AI-bug, then...

Posted: Thu Feb 25, 2010 8:38 pm
by Eric Walch
Commander McLane wrote:
Seems like an AI-bug, then...
Yep, the old line for going to the witchpoint was:

Code: Select all

(setDestinationToWitchpoint, "setDesiredRangeTo: 1000.0", setDestinationToTarget, checkCourseToDestination)
When flying towards the station the ships target is the main station. Than, when turning around, the AI correctly stets the witchpoint position as destination. The second command sets a range, but the third command sets the target position as destination. And the target is still the station. No wonder I witnessed both flying into the station. When the ship starts heading for the witchpoint there is no target yet, so I think the third command than does nothing so the witchpoint as destination stays in.