Page 1 of 2

Built In Escorts For Player Ships

Posted: Sun Sep 09, 2012 5:03 pm
by mandoman
While working on what might be my next release, the SunBird, I have been fooling around with the escort-formations randomizer oxp. I have no idea if I did it right, but this is what I put into the "World-scripts.plist":

Code: Select all

(
		"escort-formations.js"
                  ["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox);
)
I was trying to following the instructions in the ReadMe.txt, but I'm still not sure I got it right. However, my REAL question in this post is if it is possible to assign a permanent escort formation, using a particular escort ship, for the player version of the ship needing the escort. I would like make that possible for my large trader ships, but am not certain it IS possible. Does anyone know of a way to accomplish this? Thanks. :)

Re: Built In Escorts For Player Ships

Posted: Sun Sep 09, 2012 5:22 pm
by Thargoid
Basically player ships can't have escorts (of the built-in variety) - it's specifically coded against in the trunk code. The only way to do it is some sort of AI/js mixture to simulate it, as I did in Hired Guns, and has also been done in a couple of other OXPs.

Your understanding of world-script.plist is also not quite right. It's not a script file in itself, but basically it's a list of scripts within the OXP which should be run as world scripts. If you only have one such file, you can do away with the plist altogether and just call it script.js and put it in the config folder.

But if you want/need to run more than one in the oxp, as they all can't be called script.js then you use the plist to list which scripts should be run, and those scripts are put in the Scripts folder of the OXP.

For example Aquatics OXP has the following World-scripts.plist:

Code: Select all

/*
	Aquatics OXP v2.00
*/
(
	"aquatics_populator.js",
	"aquatics_equipment.js"
)
The top bit is just a comment, and the array in brackets are the world scripts (2 in this case) that should be run for this OXP.

Your line ["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox); is a function call to be used within one world script to call the function within the world script built into Escort Formations.

So what you need is your own world script (which can be either called script.js in the Config folder, or under its own name in the Scripts folder and pointed to via World-scripts.plist) which should contain the ["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox); line within a suitable function. That world script would presumably be the one that spawns the ship group in the first place.

But again as noted player ships can't have escorts in the same way that NPCs can, so it may well be a moot point anyway.[/color]

Re: Built In Escorts For Player Ships

Posted: Sun Sep 09, 2012 6:49 pm
by mandoman
Okay, I think I see what you mean, but why is it possible to hire escorts, but not possible to have them in your ship oxp with the player version? I'm not trying to be difficult, I just want to understand.

So, if I'm following you, I would have a script.js (serving as a World-script.plist) in the Config folder, and that script.js would have the entry,

Code: Select all

(
                  ["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox);
)
??? Should I also include the Scripts folder from the Escort-Formations Randomizer.oxp in my own ship's oxp, giving credit to the author in the ReadMe.txt?

Oh, and also, should I list that java script in the shipdata under the mother ship as "Scripts =", or under the escort ship listing in the same shipdata.plist file?

Re: Built In Escorts For Player Ships

Posted: Sun Sep 09, 2012 7:51 pm
by Commander McLane
world-scripts.plist is a list of (file) names of world scripts. Period. Nothing more. It's just a list of world scripts. It is therefore by definition not a world script (or any kind of script) itself. It's a list. With a file name in each line.

What do you put on this list? The file names of any world scripts that you have put in your "Scripts"-folder. Nothing else. So, if you have written a world script that is named "myFunkyWorldscript.js", you put

Code: Select all

(
   "myFunkyWorldscript.js"
)
in your world-scripts.plist. If you have written another worldscript and named it "myOtherFunkyWorldScript.js", you have to add that name to the list. Put a comma behind the first item on the list, and add the second item in the next line:

Code: Select all

(
   "myFunkyWorldscript.js",
   "myOtherFunkyWorldscript.js"
)
Do I have to go into greater detail about what a list of items is, and how it works?

Now, let's have a look at your world-scripts.plist:

Code: Select all

(
      "escort-formations.js"
                  ["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox);
)
Is it a list? If yes, how many items does it have? And if it has more than one item, are all items file names of files that reside in your "Scripts"-folder?

It appears to have one item: "escort-formations.js". That looks indeed like the file-name of a JS-script.

Now, if you want to add another item, because you have written another script, you should first put a comma behind the first item. There is no comma, which means that the whole thing is rubbish as a plist.

But even if there was a comma behind "escort-formations.js", the next line doesn't look like the name of a file inside your "Scripts"-folder. "["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox);" is obviously not a file name. Therefore it's rubbish in a list of file names.


What you have to learn is the difference between a script and a list of script file names.

If you want to write a world script (using the existing script commands with a correct syntax), then first write your script, then save it under a meaningful name inside the "Scripts"-folder of your OXP, and finally put its file name (again using the correct syntax) on the list that you have to save under the name "world-scripts.plist" in the "Config"-folder of your OXP.

Re: Built In Escorts For Player Ships

Posted: Sun Sep 09, 2012 7:55 pm
by Tricky
mandoman wrote:
Okay, I think I see what you mean, but why is it possible to hire escorts, but not possible to have them in your ship oxp with the player version? I'm not trying to be difficult, I just want to understand.
The ships that you hire as a player are just simulated escorts. They use code to follow you around and check if you are being attacked. I used this same approach with [EliteWiki] Jaguar Company, they use a script to keep formation and pass messages between themselves.
mandoman wrote:
So, if I'm following you, I would have a script.js (serving as a World-script.plist) in the Config folder, and that script.js would have the entry,

Code: Select all

(
                  ["Escort Formations Randomiser"].$setupEscortFormation(SolarWing-escort, planebox);
)
??? Should I also include the Scripts folder from the Escort-Formations Randomizer.oxp in my own ship's oxp, giving credit to the author in the ReadMe.txt?

Oh, and also, should I list that java script in the shipdata under the mother ship as "Scripts =", or under the escort ship listing in the same shipdata.plist file?
No. In the ship script for the escort you would need to place this in this.shipSpawned...

Code: Select all

this.shipSpawned = function () {
  worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship, "planebox");
};
In the escort ship data section of shipdata.plist you would have something like this...

Code: Select all

  script = "yourshipname-escort.js";
...and in the Scripts directory you would have a file named yourshipname-escort.js with all the usual setup junk that you see in the SolarWing ship script I created. You would just need that one function above and none of the others. Oh, and change the name and description and copyright and the other lines too.

EDIT: Forgot naming conflicts in the script name.

Re: Built In Escorts For Player Ships

Posted: Sun Sep 09, 2012 10:07 pm
by commanderxairon
i have been looking for that from quite a lot of time with no real responce it is a real need on oolite since you are constantly outnumbered to have a constant escort, may be actualizing hired guns to have a permanent escort contract would be nice too

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 12:53 am
by mandoman
Commander McLane wrote:
world-scripts.plist is a list of (file) names of world scripts. Period. Nothing more. It's just a list of world scripts. It is therefore by definition not a world script (or any kind of script) itself. It's a list. With a file name in each line.
Thank you Commander McLane. That was EXACTLY what I was looking for. With your explanation, and Commander Tricky's suggestions, I might be able to pull something off. Very much appreciated, guys. :)

Had to add this. Is this what it should look like, Commanders?

Code: Select all

this.name = "Solarwing-escort_formation";
this.author = "mandoman";
this.copyright = "© 2012 MandoTech Industries, Inc.";
this.license = "CC BY-NC-SA 3.0";
this.description = "Ship script for SolarWing-escort formation.";
this.version = "1.0";

this.ship = "SolarWing-escort";

this.shipSpawned = function () {
  worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship, "planebox");
};

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 6:09 am
by Tricky
Take out the line...

Code: Select all

this.ship = "SolarWing-escort";
otherwise, should work as a ship script. (Don't add to the world-script.plist file)

this.ship is automatically assigned by Oolite and is a reference to the ship object. With that reference you can access all the properties and methods of the Image Ship object.

(The geeks shall inherit the methods and properties of object Earth)

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 6:55 am
by cim

Code: Select all

worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship, "planebox");
One minor point about this line: the escort formation is decided in Oolite by the ship being escorted, not the ship doing the escorting.

I think from what you've said the Solar Wings are supposed to be the escorts, not the escorted. If so, you need to change this.ship in this line to be the escorted ship this.ship.group.leader.

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 1:09 pm
by mandoman
Tricky wrote:
Take out the line...

Code: Select all

this.ship = "SolarWing-escort";
otherwise, should work as a ship script. (Don't add to the world-script.plist file)
I was afraid of that. You see, that is the reason I shouldn't mess with other people's work. Thanks Tricky. :D
cim wrote:

Code: Select all

worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship, "planebox");
One minor point about this line: the escort formation is decided in Oolite by the ship being escorted, not the ship doing the escorting.

I think from what you've said the Solar Wings are supposed to be the escorts, not the escorted. If so, you need to change this.ship in this line to be the escorted ship this.ship.group.leader.
That oxp is yours, isn't it cim? I was wondering if you would chime in. So the line should read

Code: Select all

worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship.group.leader, "planebox");
???

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 1:22 pm
by cim
Yes, that's correct. Even better, thinking about it, would be:

Code: Select all

if (worldScripts["Escort Formations Randomiser"]) {
    worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship.group.leader, "planebox");
}
This checks that the Escort Formations worldscript is installed, and then only if it is installed, asks it to set up the escort formation.

Without that check, you'll get a bunch of errors in Latest.log if the ship is installed but Escort Formations isn't. With it, it'll use Escort Formations if it's available, and not break if it isn't.

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 1:36 pm
by mandoman
cim wrote:
Yes, that's correct. Even better, thinking about it, would be:

Code: Select all

if (worldScripts["Escort Formations Randomiser"]) {
    worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship.group.leader, "planebox");
}
This checks that the Escort Formations worldscript is installed, and then only if it is installed, asks it to set up the escort formation.

Without that check, you'll get a bunch of errors in Latest.log if the ship is installed but Escort Formations isn't. With it, it'll use Escort Formations if it's available, and not break if it isn't.
Oh, okay, I'll change it to what you have above, though I do have the Escort Formations oxp installed. It's a darn good idea, once one gets on to using it. Thanks cim. :)

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 7:34 pm
by Tricky
If the Solar Wing OXP is going to use the Escort Formations Randomiser OXP then it may be an idea to include that OXP in the package plus include something in the readme about it.

Re: Built In Escorts For Player Ships

Posted: Mon Sep 10, 2012 7:54 pm
by mandoman
Tricky wrote:
If the Solar Wing OXP is going to use the Escort Formations Randomiser OXP then it may be an idea to include that OXP in the package plus include something in the readme about it.
Yeah, I hadn't thought of that. I was more trying to form up an escort of SolarWiings for a large trader ship I'm working on, and thus hoping to make it so the player version could have those escorts, but I'm told it can't be done. I'll look into putting it into the escort version in the SolarWing oxp, though. Thanks again, Tricky. :D

Re: Built In Escorts For Player Ships

Posted: Sat Sep 15, 2012 5:54 pm
by mandoman
I've been working on this script, not changing anything, only adding to it, because the Latest.log keeps telling me:

Code: Select all

12:52:01.123 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (Solarwing-escort_formation 1.0): TypeError: this.ship is undefined

Code: Select all

12:43:58.140 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (solarwing-escort_formation 1.0): TypeError: this.ship.group is undefined
Here is what the solarwing-escort_formation.js looks like. Remember that this is using the escort_formations.oxp for a base. I tried adding definitions for the ship, and ship.group, but I probably did it wrong, or something. It's still tripping over those two errors, though.

Code: Select all

this.name = "Solarwing-escort_formation";
this.author = "mandoman";
this.copyright = "© 2012 MandoTech Industries, Inc.";
this.license = "CC BY-NC-SA 3.0";
this.description = "Ship script for SolarWing-escort formation.";
this.version = "1.0";

this.ship.group.leader = (SunBird);

this.shipSpawned = function () {
  if (worldScripts["Escort Formations Randomiser"]) {
    worldScripts["Escort Formations Randomiser"].$setupEscortFormation(this.ship.group.leader, "planebox");
  };
}