Scripting requests

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Walbrigg
Competent
Competent
Posts: 37
Joined: Sun Dec 30, 2012 1:58 pm
Location: Beds, England

Re: Scripting requests

Post by Walbrigg »

The patch above is not intended to be included in trunk (post 1.78 or whenever) as it is -- I posted it as a demonstration that what I was suggesting was in principle quite easy. If there's going to be a change that oxp writers can start to take advantage of, it should be complete, and include a way of doing per-column alignment, and a way of setting the tab stops.

(Both of which I will write if the feedback is that it is worth doing).
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6680
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripting requests

Post by another_commander »

I have a feeling the dev team will be expanding in the not so distant future... ;-)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

Quick question - is a ship's (or entity's) energy recharge rate exposed to script (to read it at least)? If so, as what? I looked in the wiki but couldn't find anything. And if not, could it be?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripting requests

Post by cim »

Thargoid wrote:
Quick question - is a ship's (or entity's) energy recharge rate exposed to script (to read it at least)? If so, as what? I looked in the wiki but couldn't find anything. And if not, could it be?
No, it's not. Now on the list for when feature addition is open again.

(It's relatively easy to determine with a frame callback, if you need this information before 1.79...)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

Thanks. I know I can calculate it (with a callback or just a simple timer) but it's a bit of a risky faff. I'm just pondering playing with a script OXP idea which would need the info.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

One more - it looks like whilst we can identify the data key of an existing entity by entity.dataKey we can't spawn that specific entity back again by system.addShips(<shipDataKey>, 1) where <shipDataKey> is a valid data key from a shipdata.plist.

Am I missing something here, or could that functionality be added? It would be most useful to be able to swap a specific entity from a pool with an identical one where the spawning primary role is a generic populator one (pirate, thargoid, thargon etc) rather than the specific datakey one.

Or is there some way of doing this already that I'm missing?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripting requests

Post by cim »

Thargoid wrote:
One more - it looks like whilst we can identify the data key of an existing entity by entity.dataKey we can't spawn that specific entity back again by system.addShips(<shipDataKey>, 1) where <shipDataKey> is a valid data key from a shipdata.plist.
You need to enclose the dataKey in square brackets to distinguish it from a role.

Code: Select all

system.addShips("[cobramk1],1);
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

Thanks (with an additional " to your quote) - works fine. When you mentioned it I remembered the fact, but needed the prompt. Anyway it's doing what I want now.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Scripting requests

Post by Svengali »

Can we get a way to set the crew via JS? Name, origin, race, etc...
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: Scripting requests

Post by Commander McLane »

Svengali wrote:
Can we get a way to set the crew via JS? Name, origin, race, etc...
Maybe this calls for a new Crew object?
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Scripting requests

Post by JensAyton »

Internally, the crew is represented by an array of zero or more Character objects (usually one). As far as I can see, the only use of these is to put them in escape pods so you can sell them/get paid by their insurance later.
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: Scripting requests

Post by Tricky »

An example of pilot names for ships.

Ship script code...

Code: Select all

this.shipSpawned = function () {
    /* Random name for the pilot. */
    this.ship.$pilotName = expandDescription("%N [nom1]");
};

this.shipLaunchedEscapePod = function(escapepod) {
    /* Transfer pilot name to the escape pod. */
    escapepod.$pilotName = this.ship.$pilotName;
};
World script code...

Code: Select all

this.startUp = function () {
    this.$rescued = [];
};

this.shipScoopedOther = function (whom) {
    /* Save the pilot's name that was rescued. */
    if (whom.$pilotName !== undefined) {
        this.$rescued.push(whom.$pilotName);
    }
};
Pilot script code... (Referenced in characters.plist)

Code: Select all

this.unloadCharacter = function() {
    var mainScript = worldScripts["Name of your world script"],
    pilotName;

    if (mainScript.$rescued.length) {
        /* Get the name of one of the rescued pilots. */
        pilotName = mainScript.$rescued.shift();
    } else {
        /* Random name. Just in case it hasn't been set by the ship script code. */
        pilotName = expandDescription("%N [nom1]");
    }

    /* Do stuff with this name, ie...
     * player.addMessageToArrivalReport(expandDescription("You rescued " + pilotName));
     */
};
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Scripting requests

Post by Svengali »

I'm aware of this way (but a good example, Tricky). This will only work for scripted pods though and requires to setup a characters.plist. For standard ships (and resulting escape-capsules) there's no way of specifying the crew dynamically (hence the request to get a way to set the crew before they are bailing out).
Zireael
---- E L I T E ----
---- E L I T E ----
Posts: 1396
Joined: Tue Nov 09, 2010 1:44 pm

Re: Scripting requests

Post by Zireael »

Small things I think could be done to the source code:

1) Making compass_target writable.
2) Have a key for console message log just like there's ~ for comms log.
3) Separate shields_recharge_rate from energy_recharge_rate

Less pressing ideas for some future OXPs:
1) Being able to specify illegal goods on a per-system basis
2) Guuys, there's 4 more function keys after F8, they could be used for something useful in the future.
User avatar
Disembodied
Jedi Spam Assassin
Jedi Spam Assassin
Posts: 6885
Joined: Thu Jul 12, 2007 10:54 pm
Location: Carter's Snort

Re: Scripting requests

Post by Disembodied »

Zireael wrote:
Being able to specify illegal goods on a per-system basis
Have you tried the [wiki]New Cargoes[/wiki] OXP? Although it deals with special cargo types, there are some system-specific differences as to what's legal and what's not.
Post Reply