Page 4 of 5

Re: Split: viewDirectionChanged woes

Posted: Mon Aug 01, 2011 8:47 pm
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.

Re: Split: viewDirectionChanged woes

Posted: Mon Aug 01, 2011 10:36 pm
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;.

Re: Split: viewDirectionChanged woes

Posted: Tue Aug 02, 2011 6:29 am
by Killer Wolf
cheers all, will update tonight, hopefully.

Re: Split: viewDirectionChanged woes

Posted: Mon Aug 08, 2011 11:32 pm
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. :?

Re: Split: viewDirectionChanged woes

Posted: Tue Aug 09, 2011 2:20 am
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.]

Re: Split: viewDirectionChanged woes

Posted: Tue Aug 09, 2011 2:28 am
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!

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 1:11 am
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.

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 2:19 am
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;
	}

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 2:24 am
by BladeRunner
Cheers, I take it with the example viewdirectionchange code, it will be automatically overridden in dock?

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 4:25 am
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?

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 4:34 am
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?

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 5:55 am
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";
}

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 8:30 am
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"
)

Re: Split: viewDirectionChanged woes

Posted: Sat Jun 20, 2015 8:36 am
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!

: ]

Re: Split: viewDirectionChanged woes

Posted: Sun Jun 21, 2015 2:35 am
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