Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Scripting requests

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

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 »

Commander McLane wrote:
Is it possible to make the '@' placeholders in descriptions.plist accessible in JS?
In oolite-locale-functions.js, I do this manually: string = currencyFormat.replace("%@", string);. I don’t plan to provide a more convenient way to do this, though.

In fact, I want to do away with the %@s and use [named_expansions] throughout for Oolite 2. They’re easier to read, and using user-provided strings with the %@ expansion mechanism is somewhat unsafe. (Actually, it’s bloody dangerous, at least under GNUstep. There’s a very dangerous feature of this type of formatting string that’s deliberately left out of the Objective-C version in Mac OS X. I hadn’t thought to check, but unfortunately it is implemented in GNUstep. I’m going to add extra verification code to filter it out.)

For reference, the way to use custom named expansions in JavaScript is:

Code: Select all

var expanded = expandDescription("Text with [named_expansion].", { named_expansion: "replaced text" });
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 »

In other words: I can use global.formatCredits(10, true, true) to format the number according to my localization, but I can't combine this with the localized version of the string 'Bounty: '. Correct?
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 »

Commander McLane wrote:
In other words: I can use global.formatCredits(10, true, true) to format the number according to my localization, but I can't combine this with the localized version of the string 'Bounty: '. Correct?
Not correct, it’s just extra work.

Code: Select all

expandDescription("[bounty-@-total-@]").split("\n")[0].replace("%@", formatCredits(10, true, true))
The split("\n")[0] gives you the first line, because the second line says “Total: %@”. I’m not sure how, but you seem to have missed that.
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 »

Ahruman wrote:
The split("\n")[0] gives you the first line, because the second line says “Total: %@”. I’m not sure how, but you seem to have missed that.
Oops! I 'missed' (rather I accidentally deleted :oops: ) the second line when I did my localization. In my German Oolite it isn't there. That's why I was wondering why the thing was named bounty-@-total-@ in the first place. :shock:

And that's why I never get a total displayed after killing something. :oops:

EDIT: To be honest, I also needed you to spoon-feed me the correct syntax. My grip on JS isn't actually that good. But now I have deducted from your line of code the complete message I want:

Code: Select all

player.consoleMessage(expandDescription("[bounty-@-total-@]").replace("%@", formatCredits(trueBounty, true, true)).replace("%@", formatCredits(player.credits, true, true)));
where trueBounty is the bounty for the current railgun kill, after accommodating the exception for asteroids. And this now looks exactly like the game-generated message. :D
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

Kaks wrote:
I think we have a bug! :)

I changed that function to

Code: Select all

   this.viewDirectionChanged = function(viewString)
   {
      player.commsMessage('Your view is now: ' + viewString);
   }
And it doesn't seem to fire properly in a few situations... BRB! :)
"brb"?! :-) any progress?
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 »

In addition to the view direction displays there emerged the idea to be able to distinguish between various external views. Currently the JS-methods only return VIEW_CUSTOM for any external view.

Because the custom_views array can contain totally arbitrary viewpoints, there can't be generic return values for the JS-viewDirection checks. But what could probably be done is to add another optional parameter to the custom_views array, containing a string that would be returned by JS instead of VIEW_CUSTOM. If it isn't defined, the return value would still be VIEW_CUSTOM.

The request popped up in relation to HUD making, where HUD creators would like to be able to customize special ship HUDs not only for the different standard (internal) view directions, but also for different external (or custom) views.
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: Scripting requests

Post by CommonSenseOTB »

In the pursuit of the creation of new types of hud gauges it has come to my attention that weapon temperature and altitude have no output to JS and therefore the values can't be used in the the creation of new gauges. This has applications in the creation of numeric, needle(analogue) , and various types of animated(button) gauges. In addition it has direct application to allow cleaning up/better drawing of the rounded pie gauges to eliminate the trailing edge on the circumference. Currently it appears I will not be able to improve the weapon temperature and altitude versions of the rounded pie gauges unless there is a JS value to read. I would therefore like to have this added as a feature request if possible.
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
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 »

CommonSenseOTB wrote:
In the pursuit of the creation of new types of hud gauges it has come to my attention that weapon temperature and altitude have no output to JS
I already told you in the other thread that you can calculate altitude in JS as distance of the player ship to the closest celestial body minus the radius of that body. So you don't need an additional JS-property for altitude.
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: Scripting requests

Post by CommonSenseOTB »

Commander McLane wrote:
CommonSenseOTB wrote:
In the pursuit of the creation of new types of hud gauges it has come to my attention that weapon temperature and altitude have no output to JS
I already told you in the other thread that you can calculate altitude in JS as distance of the player ship to the closest celestial body minus the radius of that body. So you don't need an additional JS-property for altitude.
Thankyou Commander McLane the point was well taken however I was only thinking that the bar gauges already have a variable that they are using and that having a JS of them to read might not be a difficult addition. These would then allow created gauges to use the exact same values and simulate the same units or scale. Developers of all oxp's may also benefit not just huds. Hud developers even myself may find it cumbersome and difficult to aquire altitude consistently in the manner suggested. Novices will have much difficulty. As it is, weapon temperature will still be needed so why not provide both? This IS only a request to add a feature. In the meantime I will not have a choice as either fitered entities or an array of all planetary bodies or somesuch(probably a simple solution) will provide the solution to altitude. I have yet to research the exact solution fully. (For testing purposes I have been using a simple reference to the mainPlanet as my primary focus right now is developing the numeric gauge itself.) One must keep in mind the effect of oxp's that add plenetary bodies to the system. Weapon temperature ,however, is out of reach for now.
If you really want to help a fellow oxp' er out :) please feel free to offer up a tried or tested routine that works properly under all conditions. Scripting is not my strong suit. Only just started scripting in November. How strong could it be? Time permitting I WILL find the correct solution but if one is already available and in use ,specifically, it would save me some time and help future hud developers to have tested code involved. As it is creating new hud gauges is very time consuming and difficult considering the hardcoded restrictions.
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: Scripting requests

Post by Kaks »

Killer Wolf wrote:

"brb"?! :-) any progress?
It turns out my concept of time is 'slightly' different to earth based clocks...

I did make the necessary adjustments to the code, but a couple of things (or three) distracted me from committing those changes when I had the opportunity to do so.

At the moment I'm 'a few' miles away from my oolite computer - so I've little chance of doing much Oolite dev stuff for the next couple of weeks... the fix should be there in .3, though!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Scripting requests

Post by Okti »

Hi,

I find the AI's in certain stages returns two messages at once for the outcome, as an example 'TARGET_DESTROYED' and 'TARGET_LOST' is added to the message stack at the same, and TARGET_LOST always has the high priority. So it is not easy to understand if the target is destroyed at one glance.

I try to overcome those situations by checking in JS if actual target is destroyed or not.

Another way is to use another state in the AI, to find out what happened really.

I know we are in a future freeze state at the moment, but a javascript object for the pending messages in AI and methods to remove individual ones may solve most of the problems I believe.

Thanks
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripting requests

Post by Eric Walch »

You are right that the message order is not always whet you wish. In this case it does not really matter for most of the AI if you get a 'TARGET_DESTROYED' or 'TARGET_LOST'. The reaction will probably be the same. The first is generated first but handled later. As you already noticed, does the destruction trigger first and JS will react on it first. Changing that will potentially crippling existing AI.
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Scripting requests

Post by Okti »

Eric Walch wrote:
You are right that the message order is not always whet you wish. In this case it does not really matter for most of the AI if you get a 'TARGET_DESTROYED' or 'TARGET_LOST'. The reaction will probably be the same. The first is generated first but handled later. As you already noticed, does the destruction trigger first and JS will react on it first. Changing that will potentially crippling existing AI.
You are right about it may cripple the existing AI's, but a read only array of deferred messages on the ships AI, when it goes to another state may help to understand what happened in the previous state actually script wise.

As an example State1 may require a DESIRED_RANGE_ACHIEVED, and the second one may require that as well, if DESIRED_RANGE_ACHIEVED is in the deferred messages from the first stage, it confuses the AI.
My OXP's
And Latest Mission Coyote's Run
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripting requests

Post by Eric Walch »

Okti wrote:
a read only array of deferred messages on the ships AI, when it goes to another state may help to understand what happened in the previous state actually script wise.
When the deferred messages are not yet in the executing array, they can be removed with a "dropMessages: " command. And I think it should work in your example to remove the message that could be there.

I don't know if the deferred messages can be read by script. The target inspector for the mac does list that array with pending message, but JS can not access it as far as I know.

But you are right that complex scripting confuses AI quite fast. As soon as the task becomes difficult, JS is the way to go.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

Kaks wrote:
Killer Wolf wrote:

"brb"?! :-) any progress?
It turns out my concept of time is 'slightly' different to earth based clocks...

I did make the necessary adjustments to the code, but a couple of things (or three) distracted me from committing those changes when I had the opportunity to do so.

At the moment I'm 'a few' miles away from my oolite computer - so I've little chance of doing much Oolite dev stuff for the next couple of weeks... the fix should be there in .3, though!
Just got the beta, still not working.
Post Reply