Split: viewDirectionChanged woes

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

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

Split: viewDirectionChanged woes

Post by CommonSenseOTB »

Moderator: Split from Scripting Requests discussion in Suggestion Box.
Kaks wrote:
OK, from tonight's build .viewDirectionChanged should fire correctly. It took me a while to figure out the source of glithches that were plaguing my original implementation...
Thanks. :D
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
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

cheers Kaks, give that a try when i can - the download page is refusing to load :-/
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

okay, still not working.
here's my script :

Code: Select all

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 && player.viewString != "VIEW_GUI_DISPLAY") // 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 && player.viewString != "VIEW_GUI_DISPLAY") // and under attack and not using the damaged HUD
            {
            player.ship.hud = "phantomCombatHUD.plist"; // set the combat HUD
            }
         break;
         }
		case 4:
		  {
		  if (viewString == "VIEW_GUI_DISPLAY")
		    {
					player.ship.hud = "phantomGUI.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()
      }
   }
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripting requests

Post by Wildeblood »

Killer Wolf wrote:
okay, still not working.
here's my script :

Code: Select all

this.alertConditionChanged = function(newCondition, oldCondition)
   {
   switch(newCondition)
      {
      case 0: // we're docked
 ...
		case 4:
		  {
		  if (viewString == "VIEW_GUI_DISPLAY")
		    {
					player.ship.hud = "phantomGUI.plist";
There is no alert condition 4. Your options are 0-3.
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 »

Never mind that!

I'm not surprised it's not working, KW's code hasn't got this.viewDirectionChanged anywhere I can see...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripting requests

Post by Wildeblood »

Kaks wrote:
Never mind that!

I'm not surprised it's not working, KW's code hasn't got this.viewDirectionChanged anywhere I can see...
No, because he has mistaken this.alertConditionChanged for magic.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

Wildeblood wrote:
Kaks wrote:
Never mind that!

I'm not surprised it's not working, KW's code hasn't got this.viewDirectionChanged anywhere I can see...
No, because he has mistaken this.alertConditionChanged for magic.
or maybe i just tried changing some code? pardon me for not being a fkng JS expert.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripting requests

Post by Wildeblood »

Killer Wolf wrote:
Wildeblood wrote:
Kaks wrote:
Never mind that!

I'm not surprised it's not working, KW's code hasn't got this.viewDirectionChanged anywhere I can see...
No, because he has mistaken this.alertConditionChanged for magic.
or maybe i just tried changing some code? pardon me for not being a fkng JS expert.
Don't react like that, my comment was deadpan irony, not an outrageous insult. JS isn't magical, it's just evil and bogus. But you have misunderstood the nature of either (1) events like alertConditionChanged and viewDirectionChanged or (2) what a switch/case structure does.

Apparently, JS is an event-driven object-oriented language, whatever the hell that means. So every so often the game will send an event like alertConditionChanged or viewDirectionChanged, and you have to write some code that listens out for the particular event you're interested in. There's no point listening for:-

this.alertConditionChanged = function(newCondition, oldCondition)

if you're actually interested in:-

this.viewDirectionChanged = function(viewString)

So I think all you need is this:-

Code: Select all

this.viewDirectionChanged = function(viewString)
   {
   if (viewString == "VIEW_GUI_DISPLAY")
          {
               player.ship.hud = "phantomGUI.plist";
          }
   }
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

'kay, my bad. thanks for the info, i'll hammer together something when i get home. as i've mentioned before, i don't get this OO stuff at all, lol, i'm a COBOL/BASIC creature myself :-/
really need to hunt out some basic/intro tutes on the net or something, but i just haven't got the time due to all my other art/ship building/writing etc etc.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

pointers in the right direction please : why's this brining up the GUI HUD for Aft/Port/etc?

Code: Select all

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 && player.viewString != "VIEW_GUI_DISPLAY") // 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 && player.viewString != "VIEW_GUI_DISPLAY") // and under attack and not using the damaged HUD
            {
            player.ship.hud = "phantomCombatHUD.plist"; // set the combat HUD
            }
         break;
         }
     }
   }
   
  new stuff :-


 this.viewDirectionChanged = function(viewString)
   {
   if(player.viewString = "VIEW_GUI_DISPLAY")
         {
               player.ship.hud = "phantomGUI.plist";
		 }
	else if(player.alertHostiles && player.ship.energy > 108 && player.viewString != "VIEW_GUI_DISPLAY")
		{
			player.ship.hud = "phantomCombatHUD.plist";
		}
	else if(player.ship.energy < 109)
		{
		player.ship.hud = "phantomSnafuHUD.plist";
		}
	else
		{
		player.ship.hud = "phantomNormalHUD.plist";
		}
	}

end of new stuff

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()
      }
   }
the bold bit's the bit i've added in to the rest of the original script. i was a bit off w/ the nested IF...ELSE syntax but this version is from a tute site on the web.
edit, no it's not, bold ain't working in a code snippet, so i've written it in manually.

cheers in advance....
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripting requests

Post by Thargoid »

You've got "player.viewString" where you should have just "viewString" in the first if statement in the this.viewDirectionChanged function, plus you also need == or === in an if statement, not single =. The passed parameter is just viewString, no player prefix.
Change

Code: Select all

if(player.viewString = "VIEW_GUI_DISPLAY")
         {
               player.ship.hud = "phantomGUI.plist";
       }
to

Code: Select all

if(viewString === "VIEW_GUI_DISPLAY")
         {
               player.ship.hud = "phantomGUI.plist";
       }
and similarly just below it in the next if statement down.

In the if statement the === means strictly equal to (exact same value, and exactly the same type - boolean, integer, float, string etc) whereas == does comparisons between different types and is less strict, so 2 == "2" is true, but 2 === "2" is false (but == can take longer in script runtime than === does due to the extra checking needed). More details of that are here and in many other websites - search javascript comparison for alternative websites.[/color]
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Re: Scripting requests

Post by Killer Wolf »

cheers bud, i'll try again when i get home.

edit : didn't work.
changed the new stuff to

Code: Select all

   this.viewDirectionChanged = function(viewString)
   {
   if(viewString === "VIEW_GUI_DISPLAY")
         {
               player.ship.hud = "phantomGUI.plist";
		 }
	else if(player.alertHostiles && player.ship.energy > 108 && viewString != "VIEW_GUI_DISPLAY")
		{
			player.ship.hud = "phantomCombatHUD.plist";
		}
	else if(player.ship.energy < 109)
		{
		player.ship.hud = "phantomSnafuHUD.plist";
		}
	else
		{
		player.ship.hud = "phantomNormalHUD.plist";
		}
	}
the GUI doesn't come up on view direction changes now, but neither does it come up for F5~F8.

BTW, in the log i'm also getting

Code: Select all

17:42:24.529 [debugTCP.disconnect]: No connection to debug console: "Connection to debug console failed: 'No connection could be made because the target machine actively refused it.

' (outStream status: 7, inStream status: 7)."
17:42:24.529 [debugTCP.disconnect]: No connection to debug console: "Connection to debug console failed: 'unknown error.' (outStream status: 0, inStream status: 0)."
17:42:24.529 [debugTCP.connect.failed]: Failed to connect to debug console at address 127.0.0.1:8563.
which i assume is not related?

cheers...
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 »

Killer Wolf, if you want I can try to help you as best I can. In doing the Sniper Camera System I found that it works best to only use viewDirection when going between views or going into or out of a specific view. When I want to react to a screen change for instance to go from any view to f5-f8 I use:

this.guiScreenChanged = function()
{
if(guiScreen !== "GUI_SCREEN_MAIN")
{
your code here.

or to go from f5-f8 to any view I use:(currently haven't used this one but should work)

this.guiScreenChanged = function()
{
if(guiScreen === "GUI_SCREEN_MAIN")
{
your code here.

for going to a specific view from any other view(or screen) I use:

this.viewDirectionChanged = function(to, from)
{
if(to === "VIEW_FORWARD" && from !== "VIEW_FORWARD")
{
your code here.

for going to any other view(or screen) from a specific view I use:

this.viewDirectionChanged = function(to, from)
{
if(to !== "VIEW_FORWARD" && from === "VIEW_FORWARD")
{
your code here.

When I saw your code posted awhile ago with viewString I tried it but couldn't get it to work. Without "to && from" I would use:

this.viewDirectionChanged = function()
{
if(viewDirection === "VIEW_FORWARD")
{
your code here.

One thing to remember is that this.guiScreenChanged = function() only fires on a screen change and this.viewDirectionChanged = function(to, from) only fires on a views change. As I understand it. Hopefully I listed everything correctly.

I hope this helps you out. Can't wait to see more built-in huds in your excellent ships. If this doesn't help feel free to PM me the link for the files and I will fix it for you ASAP first priority over everything else I'm currently doing. I don't want to see you waste your time on this when you could be modelling and texturing some cool ships. Cheers. :D
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 »

Your second error: looks like you've got a (new?) firewall blocking communications between Oolite & the console, or maybe you've turned the js console off - if it's the second case, your error message is just confirming that when Oolite tried to talk to the js console, it just couldn't find it...

Hmmm, this thread seems to have become anything other than scripting requests in the last few posts... A_C, what do you think? Split to a new thread?
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Re: Split: viewDirectionChanged woes

Post by another_commander »

OK, split.
Post Reply