Sign in to follow this  
martinlest2

What defines a switch default on or default off?

Recommended Posts

Hi. I am trying to work out why some toggled switches are off by default when an aircraft is loaded and some are on. Probably obvious, but I am not very advanced in this, so apologies in advance.

 

I assume (?) that the the switch xml just defines what appears in the panel, rather than its state? (As an example, this three-way battery switch is always on by default. Why is that, and how would you change it to default 'nul' position', or 'off'? Where is the definition for the state of the switch at startup?

 

Many thanks for any help!

 

Martin

<Gauge Name="Battery Switch" Version="1.0">
  <Element>
    <Visible>(L:SHOW_LIGHTS_EP, bool)</Visible>
    <Element>
      <Image Name="switch_w_off.bmp" Bright="Yes"/>
    </Element>

    <Element>
      <Position X="0" Y="0"/>
      <Select>
        <Value>(L:BATTERY_MASTER, enum)</Value>
        <Case Value="0">
          <Image Name="switch_w_on.bmp" Bright="Yes"/>
        </Case>
        <Case Value="1">
          <Image Name="switch_w_nul.bmp" Bright="Yes"/>
        </Case>
      </Select>
    </Element>
  </Element>

  <Element>
    <Visible>(L:SHOW_LIGHTS_EP, bool) ! </Visible>
    <Element>
      <Image Name="switch_w_off.bmp"/>
    </Element>

    <Element>
      <Position X="0" Y="0"/>
      <Select>
        <Value>(L:BATTERY_MASTER, enum)</Value>
        <Case Value="0">
          <Image Name="switch_w_on.bmp"/>
        </Case>
        <Case Value="1">
          <Image Name="switch_w_nul.bmp"/>
        </Case>
      </Select>
    </Element>
  </Element>

  <Mouse>
    <Area Left="0"  Width="30" Top="0" Height="23">
      <Cursor Type="UpArrow"/>
      <Click>
        (L:BATTERY_MASTER, enum) 0 > if{ (L:BATTERY_MASTER, enum) -- (>L:BATTERY_MASTER, enum) 1 (>L:VCOL_CLICK_1,enum) }
      </Click>
    </Area>
    <Area Left="0" Width="30" Top="24" Height="23">
      <Cursor Type="DownArrow"/>
      <Click>
        (L:BATTERY_MASTER, enum) 2 < if{ (L:BATTERY_MASTER, enum) ++ (>L:BATTERY_MASTER, enum) 1 (>L:VCOL_CLICK_1,enum) }
      </Click>
    </Area>
  </Mouse>
</Gauge>


Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

In your case above you are using L:Vars for some kind of logic behind FS. These will default to 0 on plane load whereas the use of the stock FS variables for display elements will show the state of FS as it is. When using L:Vars for logic to control FS actions and element displays it is a good idea to initialize the L:Var(s) to reflect the state of FS on gauge load. An example, not related to any logic you may have in the system...

 

----------------------------------------------------------------------------------------------------------------------------------------------------

 

 <Gauge Name="Battery Switch" Version="1.0">
<!-- INITIALIZATION SECTION, DO ONCE AT GAUGE LOAD -->
<Update>
    (G:Var1) 0 == if{ (A:ELECTRICAL MASTER BATTERY, bool) ! (>L:BATTERY_MASTER, enum) 1 (>G:Var1) }
</Update>
<!-- END INITIALIZATION SECTION -->

<Element>
        <Visible>(L:SHOW_LIGHTS_EP, bool)</Visible>
      <Element>
          <Image Name="switch_w_off.bmp" Bright="Yes"/>
      </Element>

....... And on & on & on

Share this post


Link to post
Share on other sites

Many thanks for the reply.

 

I have edited the xml file and recompiled the .cab with cab file editor. Unfortunately, I can't after several attempts, end up with a panel with the battery gauge (in this case) showing - there is a just a black space where the switch should be. No idea what I am doing wrong. (I am using LZX type compression; that's right, no?).

 

:nea: M

Share this post


Link to post
Share on other sites

See this post about cabbing, there's no need to redo it every time. As for compression I have no clue as I just use the provided "SDK\SimObject Creation Kit\Cabdir SDK\Cabdir.exe" and just drag the folder there and it creates it back.

 

As for not showing up it could be the cabbing or something bad in the xml. Uncab it and drag the xml into an open Internet Explorer / Chrome etc.. browser window. It will parse the code and give an error (and clue) if there are any.

Share this post


Link to post
Share on other sites

Ah yes, I remember now, I don't need to recab - had stupidly forgotten FS will use the folder of xml files (of course it will -  I don't always cab gauge folders I make!). Thanks for the reminder!

 

Parsing gives this:

 

XML Parsing Error: mismatched tag. Expected: </Element>.

Line Number 81, Column 3:

 

</Gauge>
--^

 

but I don't understand what it's telling me I'm afraid. I don't need </Element> at the end..

 

Thanks again

Share this post


Link to post
Share on other sites

Without seeing the actual XML script, it is not possible to diagnose  with any accuracy! :nea:

Share this post


Link to post
Share on other sites

I posted the xml script (complete) as above. How exactly was I to incorporate the extra bit, just as a 'header'? Maybe you could copy and paste from the above to post the entire xml file and I can compare with what I have (not at home to get the file to post).

 

Thank you!

Share this post


Link to post
Share on other sites

I've edited both your post and Roman's to use the XML code box making it easier to read.

I see nothing wrong with your XML script at all. The reference in the error report to "Line 81 Column 3" isn't helpful at all. Even allowing for some extra blank lines, as it is now there are only 55 lines or so! :nea:

Share this post


Link to post
Share on other sites

Thanks Bill.
 
The whole code, when dragged into Chrome, gives me an error (line 69 column 8 is the last character of the code):
 

This page contains the following errors:

error on line 69 at column 9: Extra content at the end of the document
Below is a rendering of the page up to the first error.
 
(G:Var1) 0 == if{ (A:ELECTRICAL MASTER BATTERY, bool) ! (>L:BATTERY_MASTER, enum) 1 (>G:Var1) } (L:SHOW_LIGHTS_EP, bool)(L:SHOW_LIGHTS_EP, bool) (L:BATTERY_MASTER, enum) (L:SHOW_LIGHTS_EP, bool) ! (L:BATTERY_MASTER, enum) 
(L:BATTERY_MASTER, enum) 0 > if{ (L:BATTERY_MASTER, enum) -- (>L:BATTERY_MASTER, enum) 1 (>L:VCOL_CLICK_1,enum) } (L:BATTERY_MASTER, enum) 2 < if{ (L:BATTERY_MASTER, enum) ++ (>L:BATTERY_MASTER, enum) 1 (>L:VCOL_CLICK_1,enum) }

Share this post


Link to post
Share on other sites

That is truly odd. I just copy/pasted your script from the first post and saved it. I dragged the XML file into Chrome and found no errors at all... :unknw:

 

You might try opening the .xml file in a hex editor and see if any strange characters show up at the bottom of the file.

 

What program are you using to create/edit .xml files? Are you sure they are not being saved in Unicode format?

Share this post


Link to post
Share on other sites

xml files are saved as Windows 1252 - does that make sense? I'll have another try tomorrow anyway.

Share this post


Link to post
Share on other sites

I still get a 'black hole' where the gauge used to be. It's not the encoding - I opened the original gauge with Editpad (and also Notepad) and saved it with no changes and it still works fine. When I add the text suggested, I get the hole where the gauge was. In any case, I have made one or two small changes to other xml files in the same cab file, re-saved them, and they still work, so no idea what the problem is in this case.

 

Am I adding the text in the right place?? What does the whole script look like, just to be sure?

 

Thanks...

Share this post


Link to post
Share on other sites

Try this version:

<Gauge Name="Battery Switch" Version="1.0">

  <!-- INITIALIZATION SECTION, DO ONCE AT GAUGE LOAD -->
  <Update>
    (G:Var1) 0 == if{ (A:ELECTRICAL MASTER BATTERY, bool) (>L:BATTERY_MASTER, enum) 1 (>G:Var1) }
  </Update>
  <!-- END INITIALIZATION SECTION -->
  
  <Element>
    <Visible>(L:SHOW_LIGHTS_EP, bool)</Visible>
    <Element>
      <Image Name="switch_w_off.bmp" Bright="Yes"/>
    </Element>

    <Element>
      <Position X="0" Y="0"/>
      <Select>
        <Value>(L:BATTERY_MASTER, enum)</Value>
        <Case Value="0">
          <Image Name="switch_w_on.bmp" Bright="Yes"/>
        </Case>
        <Case Value="1">
          <Image Name="switch_w_nul.bmp" Bright="Yes"/>
        </Case>
      </Select>
    </Element>
  </Element>

  <Element>
    <Visible>(L:SHOW_LIGHTS_EP, bool) ! </Visible>
    <Element>
      <Image Name="switch_w_off.bmp"/>
    </Element>

    <Element>
      <Position X="0" Y="0"/>
      <Select>
        <Value>(L:BATTERY_MASTER, enum)</Value>
        <Case Value="0">
          <Image Name="switch_w_on.bmp"/>
        </Case>
        <Case Value="1">
          <Image Name="switch_w_nul.bmp"/>
        </Case>
      </Select>
    </Element>
  </Element>

  <Mouse>
    <Area Left="0"  Width="30" Top="0" Height="23">
      <Cursor Type="UpArrow"/>
      <Click>
        (L:BATTERY_MASTER, enum) 0 > if{ (L:BATTERY_MASTER, enum) -- (>L:BATTERY_MASTER, enum) 1 (>L:VCOL_CLICK_1,enum) }
      </Click>
    </Area>
    <Area Left="0" Width="30" Top="24" Height="23">
      <Cursor Type="DownArrow"/>
      <Click>
        (L:BATTERY_MASTER, enum) 2 < if{ (L:BATTERY_MASTER, enum) ++ (>L:BATTERY_MASTER, enum) 1 (>L:VCOL_CLICK_1,enum) }
      </Click>
    </Area>
  </Mouse>
</Gauge>

Share this post


Link to post
Share on other sites

Wow! Perfect!! The gauge shows and is in the off position. Hats off to you, Bill...

 

I will look closely at the code (what did you change to make it both work and for the switch to appear as normal in the panel?) and try to apply this to other gauges which are also 'on' by default.

 

If you are 'in the mood' :smile: , there is one other small problem with this panel: there are two generator switches. The left one moves between three positions, (on, off, reset), when you click on it, the right one makes the 'clicking' sound, but only moves between the top and middle (on and off) positions; it will not click downwards into the third 'reset' position. After a few seconds, both switches automatically return to the central 'off' position after selecting 'reset'. These gauges function in the sim, they are not dummy - and if they are not set properly things can go wrong in engine startup and so forth (otherwise I probably wouldn't be quite so bothered!). The problem is with the code in the first box below. This is to make both switches function individually in the VC. If I remove it, the switch clicks correctly in 3 positions in the 2D panel, but clicking either Gen1 or Gen2 in the VC makes both switches move. I post the full gauge in the second box.

 

For now I have removed the code in the first box, as I don't use the VC for startup. Any idea though how this code could be fixed (as I say, if you have the time and are in the mood!! I am testing the code myself - will post if I get a solution of course),

 

Thanks again.

 

M.


<Element>
    <Select>
        <Value>  
                  (G:Var6) (P:Local Time, seconds) < (L:OH_GEN2, enum) 2 == && if{ 1 (>L:OH_GEN2, enum) 1 (>L:VCOL_CLICK_1,enum) }
                
        </Value>
    </Select>
</Element>

The full code for this switch:

<Gauge Name="Generator Eng2" Version="1.0">
<Size X="30" Y="47"/>
 

<Element>
    <Select>
        <Value>  
                  (G:Var6) (P:Local Time, seconds) < (L:OH_GEN2, enum) 2 == && if{ 1 (>L:OH_GEN2, enum) 1 (>L:VCOL_CLICK_1,enum) }
                
        </Value>
    </Select>
</Element>


<Element>
        <Visible>(L:SHOW_LIGHTS_EP, bool)</Visible>
 
      <Element>
          <Image Name="switch_w_off.bmp" Bright="Yes"/>
    </Element>    
   
     <Element>
        <Position X="0" Y="0"/>
          <Select>
             <Value>(L:OH_GEN2, enum)</Value>
             <Case Value="0">
                <Image Name="switch_w_on.bmp" Bright="Yes"/>
             </Case>
             <Case Value="1">
                <Image Name="switch_w_nul.bmp" Bright="Yes"/>
             </Case>    
          </Select>
    </Element>    
</Element>

<Element>
        <Visible>(L:SHOW_LIGHTS_EP, bool) !</Visible>
 
      <Element>
          <Image Name="switch_w_off.bmp" />
    </Element>    
   
     <Element>
        <Position X="0" Y="0"/>
          <Select>
             <Value>(L:OH_GEN2, enum)</Value>
             <Case Value="0">
                <Image Name="switch_w_on.bmp"/>
             </Case>
             <Case Value="1">
                <Image Name="switch_w_nul.bmp"/>
             </Case>    
          </Select>
    </Element>    
</Element>


<Mouse>
             
             <Area Left="0"  Width="30" Top="0" Height="23">
             <Cursor Type="UpArrow"/>
             <Click>

                (L:OH_GEN2, enum) 0 > if{ (L:OH_GEN2, enum) -- (>L:OH_GEN2, enum) 1 (>L:VCOL_CLICK_1,enum) }
                
                
             </Click>
         </Area>
         <Area Left="0" Width="30" Top="24" Height="23">
             <Cursor Type="DownArrow"/>
             <Click>

                (L:OH_GEN2, enum) 2 < if{ (L:OH_GEN2, enum) ++ (>L:OH_GEN2, enum)  (P:Local Time, seconds) 2 + (>G:Var6) +  1 (>L:VCOL_CLICK_1,enum) }

             </Click>
         </Area>


</Mouse>


    
</Gauge>


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this