Split: viewDirectionChanged woes

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

Moderators: winston, another_commander

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Split: viewDirectionChanged woes

Post by Thargoid »

Under the this.alertConditionChanged you're setting the variables, but not actually doing anything about it. So when you go into combat (red alert, condition 3) you're setting your variable (comhud) to 1 and the rest to zero. But then there is nothing that says based on that variable being set, put the relevant HUD up.

You're only actually doing the HUD change when you change view direction - if you go into combat and then try changing your view (or go into the F5 screen and then out again, to get this.guiScreenChanged to fire) whilst at red alert you should get your combat HUD up.

What I would do (if you're doing it this way with variables) is to have this.alertConditionChanged, this.guiScreenChanged and this.viewDirectionChanged all just set variables, but then call your own function (this.setHUD or something like that) which then sets the HUD based on the value of the variables. Although again you need to be a little careful of which variables you set where, or else again you could end up with clashing function calls.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Split: viewDirectionChanged woes

Post by JensAyton »

Killer Wolf wrote:
reet : getting somewhere. ish

Code: Select all

var tradhud=0;
var normhud=0;
var comhud=0;
var snafhud=0;
Unless there’s some interesting stuff you didn’t include, these variables are in global scope, meaning they’re shared by all scripts. If another script should happen to use the same name, all sorts of jolliness might ensue. Make them properties of this instead – you can still use them by name from the functions, you just need to change these lines to this.[i]foo[/i]hud = 0;.
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: Split: viewDirectionChanged woes

Post by Killer Wolf »

cheers all, will update tonight, hopefully.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Split: viewDirectionChanged woes

Post by Switeck »

Ahruman wrote:
Killer Wolf wrote:
reet : getting somewhere. ish

Code: Select all

var tradhud=0;
var normhud=0;
var comhud=0;
var snafhud=0;
Unless there’s some interesting stuff you didn’t include, these variables are in global scope, meaning they’re shared by all scripts. If another script should happen to use the same name, all sorts of jolliness might ensue.
Is that because they are defined at the "root" of the .js script file? Because I thought var-defined variables were local to that script only. :?
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Split: viewDirectionChanged woes

Post by Capt. Murphy »

This is from a little JS tutorial site (http://www.w3schools.com/js/js_variables.asp) that I've found useful.

The bits in red are my addition....
Local JavaScript Variables

A variable declared [with 'var'] within a JavaScript function becomes LOCAL and can only be accessed within that function. (the variable has local scope).

You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared.

Local variables are destroyed when you exit the function.

You will learn more about functions in a later chapter of this tutorial.

Global JavaScript Variables

Variables declared outside a function become GLOBAL, and all scripts and functions on the web page can access it.

Global variables are destroyed when you close the page.

If you declare a variable, without using "var", the variable always becomes GLOBAL[, unless declared as this.variable = whatever where it is only GLOBAL as far as that script is conxerned.]
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Mauiby de Fug
---- E L I T E ----
---- E L I T E ----
Posts: 847
Joined: Tue Sep 07, 2010 2:23 pm

Re: Split: viewDirectionChanged woes

Post by Mauiby de Fug »

Capt. Murphy wrote:
This is from a little JS tutorial site (http://www.w3schools.com/js/js_variables.asp) that I've found useful.
My housemate's been leaning CSS, PHP and possibly a couple of other languagey things from that site - he also says it's really good!
BladeRunner
Average
Average
Posts: 13
Joined: Sat Jun 20, 2015 1:06 am

Re: Split: viewDirectionChanged woes

Post by BladeRunner »

Hi, reviving this old topic as I am wanting to have not only 'damaged' huds, but also customise the image background for each view (fore, aft, port, starboard).

Need help with getting the views customised first, specifically how to detect the view change keypress and then load a different hud.plist for that view being changed.

Any help with code examples would be appreciated, or any oxp's that already do this - please point me in the right direction!

Cheers.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Split: viewDirectionChanged woes

Post by phkb »

Your probably want this:
viewDirectionChanged

The viewDirectionChanged handler is called when the player view changes, with a string to indicate which view the player is facing. Amongst its possible values are "VIEW_FORWARD", "VIEW_AFT", "VIEW_PORT", "VIEW_STARBOARD", "VIEW_CUSTOM", "VIEW_GUI_DISPLAY".

Code: Select all

  this.viewDirectionChanged = function(viewString)
  {
    if (viewString == "VIEW_PORT")
    {
       // Your code here
    }
  }
If you create different HUD's for different views, you'll probably need something like this:

Code: Select all

	var p = player.ship;
	switch (viewString) {
		case "VIEW_FORWARD":
			p.hud = "hud_front.plist";
			break;
		case "VIEW_AFT":
			p.hud = "hud_aft.plist";
			break;
		case "VIEW_PORT":
			p.hud = "hud_port.plist";
			break;
		case "VIEW_STARBOARD":
			p.hud = "hud_starboard.plist";
			break;
	}
BladeRunner
Average
Average
Posts: 13
Joined: Sat Jun 20, 2015 1:06 am

Re: Split: viewDirectionChanged woes

Post by BladeRunner »

Cheers, I take it with the example viewdirectionchange code, it will be automatically overridden in dock?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Split: viewDirectionChanged woes

Post by phkb »

If you change the HUD, it will stay changed until you change it. Docking by itself won't do anything. Use the shipDockedWithStation event to monitor when the player docks, and then either change the HUD to a "docked" state, or ensure all the HUD plist files you create have the same "docked" settings, so regardless of which one is active when you dock, the HUD will look the same. What I mean is, you can set items in the HUD with an alertCondition, which controls which alert conditions the dial appears at. It is a number from 0 to 15, formed by adding together the numbers for the individual alert conditions - 1=docked, 2=green, 4=yellow, 8=red. So, if you have HUD items with an alertCondition of 1, they will only appear when docked. Does that make sense?
BladeRunner
Average
Average
Posts: 13
Joined: Sat Jun 20, 2015 1:06 am

Re: Split: viewDirectionChanged woes

Post by BladeRunner »

Thanks (on above) I will include a docked/not docked detection later...


OK, so I have 'view.ship.js" in the script folder:
this.name = "view-myship";
this.author = "BR";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Ship's HUD View";
this.version = "1.0";

this.viewDirectionChanged = function(viewString)
{
if (viewString === "VIEW_CUSTOM")
{
var p = player.ship;
switch (viewString) {
case "VIEW_FORWARD":
p.hud = "myship-hud-fore.plist";
break;
case "VIEW_AFT":
p.hud = "myship-hud-aft.plist";
break;
case "VIEW_PORT":
p.hud = "myship-hud-port.plist";
break;
case "VIEW_STARBOARD":
p.hud = "myship-hud-star.plist";
break;

}
}
I also have my plist's for the huds (as above)

and I have my shipdata.plist that has the following code:
<key>hud</key>
<string>myship-hud-fore.plist</string>
which loads the custom screen up just fine, but nothing else!!!

However if theshipdata.plist <hud> is given :
<string>view.myship.js</string>
and the view.myship.js file is altered to include:
this.startup = player.ship.hud = "myship-hud-fore.plist"
it defaults to vanilla hud
: P


ideas? help?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Split: viewDirectionChanged woes

Post by phkb »

I don't think you need the shipdata.plist file, unless your making the HUD for a specific ship.
And I would suggest this:

Code: Select all

//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
	player.ship.hud =  "myship-hud-fore.plist";
}
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Split: viewDirectionChanged woes

Post by spara »

BladeRunner, I might be reading you wrong, but have you defined your worldscript? If not, then the events in your script won't trigger. If this is the case then either rename your script to script.js and put it into the Config folder or alternatively create a file world-scripts.plist with the following content and put it into the Config folder.

Code: Select all

(
	"view.ship.js"
)
BladeRunner
Average
Average
Posts: 13
Joined: Sat Jun 20, 2015 1:06 am

Re: Split: viewDirectionChanged woes

Post by BladeRunner »

Yep, its for a specific ship.
-awesome tips folks.


-I had noted the worldscript elsewhere, but was not sure about it - thanks I will give them a go later today and let you know the results!

: ]
BladeRunner
Average
Average
Posts: 13
Joined: Sat Jun 20, 2015 1:06 am

Re: Split: viewDirectionChanged woes

Post by BladeRunner »

phkb wrote:
I don't think you need the shipdata.plist file, unless your making the HUD for a specific ship.
And I would suggest this:

Code: Select all

//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
	player.ship.hud =  "myship-hud-fore.plist";
}
I am putting this in the "view.myship.js" file and have added a world-scripts.plist to the config folder.

still not working.... : P
Post Reply