Split: viewDirectionChanged woes
Moderators: winston, another_commander
Re: Split: viewDirectionChanged woes
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.
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.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Re: Split: viewDirectionChanged woes
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 ofKiller Wolf wrote:reet : getting somewhere. ishCode: Select all
var tradhud=0; var normhud=0; var comhud=0; var snafhud=0;
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;
.E-mail: [email protected]
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
Re: Split: viewDirectionChanged woes
cheers all, will update tonight, hopefully.
Re: Split: viewDirectionChanged woes
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.Ahruman wrote: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.Killer Wolf wrote:reet : getting somewhere. ishCode: Select all
var tradhud=0; var normhud=0; var comhud=0; var snafhud=0;
- Capt. Murphy
- Commodore
- Posts: 1127
- Joined: Fri Feb 25, 2011 8:46 am
- Location: UK South Coast.
Re: Split: viewDirectionChanged woes
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....
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 asthis.variable = whatever
where it is only GLOBAL as far as that script is conxerned.]
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
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
- Mauiby de Fug
- ---- E L I T E ----
- Posts: 847
- Joined: Tue Sep 07, 2010 2:23 pm
Re: Split: viewDirectionChanged woes
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!Capt. Murphy wrote:This is from a little JS tutorial site (http://www.w3schools.com/js/js_variables.asp) that I've found useful.
-
- Average
- Posts: 13
- Joined: Sat Jun 20, 2015 1:06 am
Re: Split: viewDirectionChanged woes
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.
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.
- phkb
- 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
Your probably want this:
If you create different HUD's for different views, you'll probably need something like 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 } }
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;
}
-
- Average
- Posts: 13
- Joined: Sat Jun 20, 2015 1:06 am
Re: Split: viewDirectionChanged woes
Cheers, I take it with the example viewdirectionchange code, it will be automatically overridden in dock?
- phkb
- 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
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?-
- Average
- Posts: 13
- Joined: Sat Jun 20, 2015 1:06 am
Re: Split: viewDirectionChanged woes
Thanks (on above) I will include a docked/not docked detection later...
OK, so I have 'view.ship.js" in the script folder:
and I have my shipdata.plist that has the following code:
However if theshipdata.plist <hud> is given :
: P
ideas? help?
OK, so I have 'view.ship.js" in the script folder:
I also have my plist's for the huds (as above)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;
}
}
and I have my shipdata.plist that has the following code:
which loads the custom screen up just fine, but nothing else!!!<key>hud</key>
<string>myship-hud-fore.plist</string>
However if theshipdata.plist <hud> is given :
and the view.myship.js file is altered to include:<string>view.myship.js</string>
it defaults to vanilla hudthis.startup = player.ship.hud = "myship-hud-fore.plist"
: P
ideas? help?
- phkb
- 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
I don't think you need the shipdata.plist file, unless your making the HUD for a specific ship.
And I would suggest this:
And I would suggest this:
Code: Select all
//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
player.ship.hud = "myship-hud-fore.plist";
}
Re: Split: viewDirectionChanged woes
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"
)
-
- Average
- Posts: 13
- Joined: Sat Jun 20, 2015 1:06 am
Re: Split: viewDirectionChanged woes
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!
: ]
-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!
: ]
-
- Average
- Posts: 13
- Joined: Sat Jun 20, 2015 1:06 am
Re: Split: viewDirectionChanged woes
I am putting this in the "view.myship.js" file and have added a world-scripts.plist to the config folder.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"; }
still not working.... : P