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
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripting requests

Post by Phasted »

Okay, as long as you asked:

Granted, this is huge (and probably well outside the scope of what you're prepared to do), but...

Is there any way to include some sort of stripped-down bare-bones browser that would give OXP writers access to client-side JS and the document object? That could be soooooo useful...
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 »

Nope.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripting requests

Post by Phasted »

It was a long shot...
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:

Post by Killer Wolf »

Thargoid wrote:
The problem you'll hit is guiScreenChanged doesn't currently trigger when you leave the F5 screen and go back to the views (F1-4) whilst in-flight. So you need a little fancy script-footwork to overcome that.

I believe this is under discussion/repair at the moment for 1.75 (from what I saw overnight) and it's something I've raised before as a glitch (I fell over it when coding the Vortex).

So currently you can change the HUD when you go into F5 whilst in-flight, but when you come out again your HUD may well not change back unless you make other arrangements.

has this been sorted?
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 »

Yep, but it wasn't on the wiki until a few minutes ago: viewDirectionChanged.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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 »

cool, cheers Kaks
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 »

As per this post, is it possible to expose things like length, width and height of an entity to JS (they're not even in shipdata, only in the DAT-file)?

As a workaround, what about things like weapon_position_foo, view_position_foo, missile_launch_position and aft_eject_position (and, while we're at it, scoop_position)? Can they be exposed to JS (presumably read-only)?
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 »

About collisionRadius, it's used by the collision detection code too: if 2 collisionRadiuses intersect (or even touch, I think), Oolite will try to figure out if a collision did take place.
However, if the collisionsRadiuses do not touch, you're 100% guaranteed that no collision can happen, at all.
In other words, you should be 'safe' spawning stuff at ship.collisionRadius + stuff.collisionRadius + 0.000001 metres away! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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 »

Kaks wrote:
In other words, you should be 'safe' spawning stuff at ship.collisionRadius + stuff.collisionRadius + 0.000001 metres away! :)
Without going so far as to actually check, I’m not 100 % sure simulation and script execution happen in the right order to actually guarantee that.
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 »

still don't work.
i added the stuff into Thargoid's script :

Code: Select all

this.name               = "kwPhantomHUDswitch.js";
this.author               = "Thargoid";
this.copyright            = "Do what you want with it";
this.description         = "Switches HUDs based on alert condition and ships energy";
this.version            = "1.0";


this.alertConditionChanged = function(newCondition, oldCondition)
   {
   switch(newCondition)
      {
      case 0: // we're docked
         {
         player.ship.hud = "phantomTradingHUD.plist"; // set the docked HUD
         break;
         }
      case 1: // we're at green alert
      case 2: // or we're at yellow alert
         {
         if(player.ship.energy > 108) // if we're not using the damaged HUD
            {
            player.ship.hud = "phantomNormalHUD.plist"; // set the standard HUD
            }
         break;
         }
      case 3: // we're at red alert
         {
         if(player.alertHostiles && player.ship.energy > 108) // and under attack and not using the damaged HUD
            {
            player.ship.hud = "phantomCombatHUD.plist"; // set the combat HUD
            }
         break;
         }
      }
   }
   

 	this.viewDirectionChanged = function(viewString)
	{
		if (viewString == "VIEW_GUI_DISPLAY")
		{
		player.ship.hud = "phantomGUI.plist";
		}
	else
		{
		player.ship.hud = "phantomNormalHUD.plist";
		}
	}
  

this.shipLaunchedFromStation = function()
   {
   if(this.energyCheckTimer)
      {
      this.energyCheckTimer.start()
      }
   else
      {
      this.energyCheckTimer = new Timer(this, this.energyCheck,0,2)      // use a timer to keep an eye on the HUD state
      }
   }


this.energyCheck = function()
   {
   if(player.ship.docked)
      {
      this.energyCheckTimer.stop();
      }
   else
      {
      if(player.ship.energy < 109 )
         {
         player.ship.hud = "phantomSnafuHUD.plist"; // display the damaged HUD
         return;
         }
      if(player.ship.energy > 108 && player.ship.hud == "phantomSnafuHUD.plist")
         {
         this.alertConditionChanged(player.alertCondition,0); // if energy is >49 and we're still displaying the damaged HUD, use other code to repair
         }
      }             
   }

this.shipDied = function()
   {
   if(this.energyCheckTimer)
      {
      this.energyCheckTimer.stop()
      }
   }
and nothing happened.
i tried a cut down version :

Code: Select all

this.name               = "kwPhantomHUDswitch.js";
this.author               = "Thargoid";
this.copyright            = "Do what you want with it";
this.description         = "Switches HUDs based on alert condition and ships energy";
this.version            = "1.0";



 	this.viewDirectionChanged = function(viewString)
	{
		if (viewString == "VIEW_GUI_DISPLAY")
		{
		player.ship.hud = "phantomGUI.plist";
		}
	else
		{
		player.ship.hud = "phantomNormalHUD.plist";
		}
	}
  
- first time out i got the normal hud, press F5, got the trading HUD instead, then took a couple more view changes before it changed back to Normal and didn't change to the Trading HUD when i docked.
second time out it didn't change to normal when i launched and it took a few presses before the Normal HUD came up.

what did i do wrong?
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 »

Well, viewDirection is for when you're in flight. It should fire exactly once if you're switching from an external view to any of the gui displays. So if you're switching from one gui display to another viewDirection doesn't do anything.

To handle all the gui displays, you still need the guiChanged events...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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 »

it fired once like i said but changed to the wrong HUD image. i don'tparticularly need the GUIchanged thing because one hud image covers all, hence the test to simply see if i'm looking at a GUI or not.
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 »

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! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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 »

lol, and there was me thinking my JS ability was rubbish!

oh hang on, it is!
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 »

A request for better localization:

Is it possible to make the '@' placeholders in descriptions.plist accessible in JS?

For instance, I want to simulate the bounty message after killing a pirate in JS. The relevant message is bounty-@-total-@ (I'm not sure what the second '@' indicates) and in the vanilla English localization its content is 'Bounty: %@', where '%@' is replaced by a number and the Cr-symbol. In a German localization it would be 'Prämie: %@' instead.

I can produce the message in JS through expandDescription("[bounty-@-total-@]") and get the localized version, but it displays '%@' instead of a meaningful value. Therefore the request: is it possible to transfer the desired value of '%@' through a parameter? So that expandDescription("[bounty-@-total-@]", 10) would display as 'Bounty: 10.0 ₢' or 'Prämie: 10,0 ₢' depending on localization?
Post Reply