Page 31 of 56

Re: Scripting requests

Posted: Thu Jan 20, 2011 4:52 pm
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...

Re: Scripting requests

Posted: Thu Jan 20, 2011 6:34 pm
by JensAyton
Nope.

Re: Scripting requests

Posted: Fri Jan 21, 2011 4:20 pm
by Phasted
It was a long shot...

Re:

Posted: Thu Apr 28, 2011 4:35 pm
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?

Re: Scripting requests

Posted: Sat Apr 30, 2011 12:01 am
by Kaks
Yep, but it wasn't on the wiki until a few minutes ago: viewDirectionChanged.

Re: Scripting requests

Posted: Sat Apr 30, 2011 6:33 am
by Killer Wolf
cool, cheers Kaks

Re: Scripting requests

Posted: Sat Apr 30, 2011 8:42 am
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)?

Re: Scripting requests

Posted: Sat Apr 30, 2011 2:10 pm
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! :)

Re: Scripting requests

Posted: Sat Apr 30, 2011 2:25 pm
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.

Re: Scripting requests

Posted: Sat Apr 30, 2011 2:35 pm
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?

Re: Scripting requests

Posted: Sat Apr 30, 2011 2:44 pm
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...

Re: Scripting requests

Posted: Sun May 01, 2011 7:20 am
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.

Re: Scripting requests

Posted: Sun May 01, 2011 12:18 pm
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! :)

Re: Scripting requests

Posted: Sun May 01, 2011 3:15 pm
by Killer Wolf
lol, and there was me thinking my JS ability was rubbish!

oh hang on, it is!

Re: Scripting requests

Posted: Thu May 05, 2011 8:37 am
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?