Page 77 of 118
Re: Scripters cove
Posted: Wed Mar 11, 2015 8:53 am
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)?
Re: Scripters cove
Posted: Wed Mar 11, 2015 8:57 am
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.
Re: Scripters cove
Posted: Wed Mar 11, 2015 9:26 am
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"]
Re: Scripters cove
Posted: Wed Mar 11, 2015 5:41 pm
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
}
Re: Scripters cove
Posted: Sat Mar 14, 2015 8:34 am
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
?
Re: Scripters cove
Posted: Sat Mar 14, 2015 9:06 am
by cim
phkb wrote:Would I use worldScripts["oolite-contracts-parcels"]._addParcelToSystem
?
Yes
Re: Scripters cove
Posted: Sun Mar 22, 2015 3:46 am
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?
Re: Scripters cove
Posted: Sun Mar 22, 2015 4:10 am
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.
}
Re: Scripters cove
Posted: Sun Mar 22, 2015 5:21 am
by phkb
Got it! Thanks, Wildeblood!
Re: Scripters cove
Posted: Sun Mar 22, 2015 8:36 am
by phkb
Is it possible to pull up a random ship class name? Eg. "Python" or "Cobra MkIII" or "Sidewinder Scout Ship".
Re: Scripters cove
Posted: Sun Mar 22, 2015 8:49 am
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.
Re: Scripters cove
Posted: Fri Apr 03, 2015 11:03 pm
by phkb
Question: what is the official rate at which ships can be launched from a station? 2 per minute? 3 per minute?
Re: Scripters cove
Posted: Sat Apr 04, 2015 6:33 am
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.
Re: Scripters cove
Posted: Sun Apr 05, 2015 5:50 am
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.
Re: Scripters cove
Posted: Sun Apr 05, 2015 7:24 am
by phkb
It's actually a pretty simple mistake, and one I often make:
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) {