Scripters cove

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

Moderators: winston, another_commander

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander »

phkb wrote:

Code: Select all

19:16:43.227 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (RenameShipTweak 1.0.0): TypeError: ship.AIScript.oolite_priorityai is undefined
Haven't had a chance to check or test, but should that not be oolite-priorityai (dash instead of underscore)?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

another_commander wrote:
but should that not be oolite-priorityai (dash instead of underscore)
I did try that, but got a different error about trying to subtract something. Looking in the oolite-priorityai.js file, there is a line that reads:this.ship.AIScript.oolite_priorityai = this;, so I think the underscore is correct.
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: Scripters cove

Post by Wildeblood »

phkb wrote:
another_commander wrote:
but should that not be oolite-priorityai (dash instead of underscore)
I did try that, but got a different error about trying to subtract something. Looking in the oolite-priorityai.js file, there is a line that reads:this.ship.AIScript.oolite_priorityai = this;, so I think the underscore is correct.
No comment about the problem at hand, but FYI when you get the "can't subtract" error use this notation:-
this.ship.AIScript["oolite-priorityai"]
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

phkb wrote:
Cim, I'm really sorry. I'm a programmer and I should be able to work this out, but I mustn't have enough caffeine in my system, or I've eaten too many dark side cookies, or something, because I can't work this out.
The problem is that ship.AIScript.oolite_priorityai won't be defined until the AI has initialised (after the AIScript's aiStarted is called). So shipSpawned is probably too early to do this.

There are two ways out of this:
1) Call it later. Set a 0.25 second timer (or a one-frame frame callback) in shipSpawned, which updates the AI.
2) Rather than updating the AI, update the AI library. Advantage: no timing issues, only needs doing once. Disadvantage: updates it for everything including non-assassin OXP AIs so you really need to document that you've done this.
In your this.startUp, do

Code: Select all

worldScripts["oolite-libPriorityAI"].PriorityAIController.prototype.conditionScannerContainsCourier = function()
{
// replacement custom code goes here
}
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Is it possible with JS to add a parcel contract to the Parcel Contracts screen? I know I can add a contract to the player via player.ship.addParcel, but can I add it to the station so the player sees the contract in the normal place?

EDIT: I think I just figured it out. Would I use worldScripts["oolite-contracts-parcels"]._addParcelToSystem?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

phkb wrote:
Would I use worldScripts["oolite-contracts-parcels"]._addParcelToSystem?
Yes
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

If I set the script on a ship using setScript, does that replace any script the ship already has, or can it be in addition to any script the ship has? For instance, if I wanted to add a single handler to a ship that already has a script, say shipDockedWithStation, can I do this without upsetting any existing script?
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: Scripters cove

Post by Wildeblood »

phkb wrote:
If I set the script on a ship using setScript, does that replace any script the ship already has, or can it be in addition to any script the ship has?
Yes, using setScript replaces the whole existing script with the contents of a specified JS file.
phkb wrote:
For instance, if I wanted to add a single handler to a ship that already has a script, say shipDockedWithStation, can I do this without upsetting any existing script?
Yes.

If you have a reference to the ship (hereinafter "theShip"), you can just add theShip.script.whatever to its existing script. e.g.

Code: Select all

var theShip = player.ship.target;
if (!theShip.script.shipDockedWithStation) {
    theShip.script.shipDockedWithStation = this._targetShipDockedWithStation;
}

Code: Select all

this._targetShipDockedWithStation = function () {
    // Your code here.
}
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Got it! Thanks, Wildeblood!
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Is it possible to pull up a random ship class name? Eg. "Python" or "Cobra MkIII" or "Sidewinder Scout Ship".
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

phkb wrote:
Is it possible to pull up a random ship class name? Eg. "Python" or "Cobra MkIII" or "Sidewinder Scout Ship".
Not very straight forward, but you can work some magic with keysForRole and shipDataForKey. Don't know your context, but also pulling ship class names from ships spawned to the system retrieved with entitiesWithScanClass (or something else that gives you a list of entities in system) might do the trick.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Question: what is the official rate at which ships can be launched from a station? 2 per minute? 3 per minute?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

phkb wrote:
Question: what is the official rate at which ships can be launched from a station? 2 per minute? 3 per minute?
Give it enough docks and you can launch them as fast as you like.

Any individual dock can't launch more than one ship every six seconds, and it may be slower in practice as it needs the ships which have launched to have cleared the area in front of the dock.
Layne
---- E L I T E ----
---- E L I T E ----
Posts: 355
Joined: Sat Mar 28, 2015 11:14 pm

Re: Scripters cove

Post by Layne »

Ok, this is driving me up the proverbial and possibly literal wall, if I can find a wall handy.

I'm trying to tinker with some oxps to improve my overall Oolite feel; the two in question are the original Constores 3.0 (the last version with the box constores) and HOopy Casinos. My goal with HOopy is to only have them present in Corporate systems-- it makes no sense to me to have them in Commie or Dictator systems even if the description says 'famed for their hoopy casinos'. Anyhow, making /any/ change to the populator script, even changing a single number without moving anything else, or erasing anything else, or changing the formatting, breaks the populator entirely. It won't load and the log shows the following:

01:28:24.887 [script.javaScript.exception.badLeftsideOfAssignment]: ***** JavaScript exception (hoopy_populator.js.anon-script): ReferenceError: invalid assignment left-hand side
01:28:24.887 [script.javaScript.exception.badLeftsideOfAssignment]: C:\Program Files (x86)/Oolite/oolite.app/GNUstep/Library/ApplicationSupport/Oolite/ManagedAddOns/oolite.oxp.Murgh.HoOpyCasino.oxz/Scripts/hoopy_populator.js, line 11: if (system.techLevel >= 11 && system.scrambledPseudoRandomNumber() > 0.55 && system.government = 7 {
01:28:24.890 [script.javaScript.load.failed]: ***** Error loading JavaScript script C:\Program Files (x86)/Oolite/oolite.app/GNUstep/Library/ApplicationSupport/Oolite/ManagedAddOns/oolite.oxp.Murgh.HoOpyCasino.oxz/Scripts/hoopy_populator.js -- compilation failed


Keep in mind I'm changing nothing else in this file except a couple of numbers and I am /not/ using notepad, because I know that messes up the formatting. (I've tried both wordpad and MS Word and they both have this same result.)

Next issue, with Constores 3.0, using the old box store models. I can use the current script for the constores to remove the shipyard/refueling per the 4.x updates, but doing so makes the constores ignore the commodities listings from the custom list, or breaks the nav/witchspace beacon billboards, but does not apparently generate any log messages to explain why.

What am I doing wrong here? Why does changing one or two numbers in the HOopy populator somehow destroy the formatting even if nothing else is moved and no spacings are changed? I'm lost here, and I'd really appreciate any advice on how this is supposed to work.
Reports of my death have been greatly underestimated.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

It's actually a pretty simple mistake, and one I often make:
Layne wrote:
system.government = 7
should read as system.government == 7. In Javascript, the "=" sign on its own is used for assigning values (ie. var x = 1;) In an "If" statement, you need to use "==" or "===". Either should do the trick.

It also looks like you're missing a bracket at the end of the if clauses.

Code: Select all

if (system.techLevel >= 11 && system.scrambledPseudoRandomNumber() > 0.55 && system.government = 7 {
should be

Code: Select all

if (system.techLevel >= 11 && system.scrambledPseudoRandomNumber() > 0.55 && system.government == 7) {
Post Reply