• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Setting L: Variables with a switch

Messages
75
Country
unitedstates
A switch which controls an L: was not working in FSX so I am remaking it using the Aces tool. It is a very simple toggle switch. click and the L: = 1 click again and it = 0. I for some reason can not seem to make this happen.

<?xml version="1.0" encoding="UTF-16"?>

<SimBase.Document
Type="AceXML"
version="1,0"
id="derich">
<Descr>AceXML Document</Descr>
<Filename>derich.xml</Filename>
<SimGauge.Gauge id="Gauge" ArtDirectory="C:\Program Files\Microsoft Games\Microsoft Flight Simulator X\SimObjects\Airplanes\SR-71A\panel\Alpha">
<FloatPosition>0.000,0.000</FloatPosition>
<Size>38,38</Size>
<Element id="Derich">
<FloatPosition>0.000,0.000</FloatPosition>
<Select id="On/Off">
<Expression id="Expression">
<Script>(L:Derich_enable , bool)</Script>
</Expression>
<Case id="Off">
<ExpressionResult>0.000</ExpressionResult>
<Image id="switchoff.bmp" Name="switchoff.bmp">
<Transparent>True</Transparent>
</Image>
</Case>
<Case id="On">
<ExpressionResult>1.000</ExpressionResult>
<Image id="switchon.bmp" Name="switchon.bmp">
<Transparent>True</Transparent>
</Image>
</Case>
</Select>
</Element>
<MouseArea id="MouseArea">
<FloatPosition>0.000,0.000</FloatPosition>
<Size>38,38</Size>
<CursorType>Hand</CursorType>
<MouseClick id="On">
<Script>(M:Event) &apos;LeftSingle+LeftRelease&apos; scmp 0 == if{ 1 (&gt;L:Derich_enable , bool) }</Script>
<ClickType>LeftSingle+LeftRelease</ClickType>
</MouseClick>
<MouseClick id="Off">
<Script>(M:Event) &apos;LeftSingle&apos; scmp 0 == if{ 0 (&gt;L:Derich_enable , bool) }</Script>
<ClickType>LeftSingle</ClickType>
</MouseClick>
</MouseArea>
</SimGauge.Gauge>
</SimBase.Document>

basically click L:Derich_enable = 1, switch goes up for on, click again L:Derich_enable = 0, switch goes back down for off. The switch will go up but L:Derich_enable doesn't = 1. I am using the handy blackbox tool. And when I click again the switch won't go back down. Thanks in advance for the help.
 
Last edited:
Hi tooLowGear,

You are defining two MouseclickEvents within one MouseArea, which is not a good idea ;)

Try something like this:
Code:
<MouseArea id="MouseArea">
  <FloatPosition>0.000,0.000</FloatPosition>
  <Size>38,38</Size>
  <CursorType>Hand</CursorType>
  <MouseClick id="On">
    <ClickType>LeftSingle</ClickType>
    <Script>
      (M:Event) 'LeftSingle' scmp 0 ==
      if{
        (L:Derich_enable,bool) ! (&gt;L:Derich_enable,bool)
      }
    </Script>
  </MouseClick>
</MouseArea>

And please use a Code tag the next time you paste code in the forum. Use the #-symbol in the toolbar for that. It's easier to read that way.

Regards
Vitus
 
Last edited:
Hi tooLowGear,

You are defining two MouseclickEvents within one MouseArea, which is not a good idea ;)

Try something like this:
Code:
<MouseArea id="MouseArea">
  <FloatPosition>0.000,0.000</FloatPosition>
  <Size>38,38</Size>
  <CursorType>Hand</CursorType>
  <MouseClick id="On">
    <ClickType>LeftSingle</ClickType>
    <Script>
      (M:Event) 'LeftSingle' scmp 0 ==
      if{
        (L:Derich_enable,bool) ! (&gt;L:Derich_enable,bool)
      }
    </Script>
  </MouseClick>
</MouseArea>

And please use a Code tag the next time you paste code in the forum. Use the #-symbol in the toolbar for that. It's easier to read that way.

Regards
Vitus

Sorry about that.

Thanks for the help. I have seen the "(L:Derich_enable,bool) ! (&gt;L:Derich_enable,bool)" type of coding before. What exactly does that mean? Correct me if I am wrong but I interpret that as (L:Derich_enable,bool) = NOT (L:Derich_enable,bool). So when I click that sets it to not what it was, which based on the 2 case values, limits the output to 1 or 0?

Plumbing and reverse polish are dark arts.

Thanks!

update: Vitus, The code works wonderfully, Thank you. However the image does not update with the (L:Derich_enable,bool) value as listed in the switch cases. I suspect more learning is about to occur.

Code:
<?xml version="1.0" encoding="UTF-16"?>

<SimBase.Document
        Type="AceXML"
        version="1,0"
        id="derich">
    <Descr>AceXML Document</Descr>
    <Filename>derich.xml</Filename>
    <SimGauge.Gauge id="Gauge" ArtDirectory="C:\Program Files\Microsoft Games\Microsoft Flight Simulator X\SimObjects\Airplanes\ALPHA SR-71A 2008\panel.Widescreen\Alpha">
        <FloatPosition>0.000,0.000</FloatPosition>
        <Size>38,38</Size>
        <Element id="Derich">
            <FloatPosition>0.000,0.000</FloatPosition>
            <Select id="On/Off">
                <Expression id="Expression">
                    <Script>(L:Derich_enable , bool)</Script>
                </Expression>
                <Case id="Off">
                    <ExpressionResult>0.000</ExpressionResult>
                    <Image id="switchoff.bmp" Name="switchoff.bmp">
                        <Transparent>True</Transparent>
                    </Image>
                </Case>
                <Case id="On">
                    <ExpressionResult>1.000</ExpressionResult>
                    <Image id="switchon.bmp" Name="switchon.bmp">
                        <Transparent>True</Transparent>
                    </Image>
                </Case>
            </Select>
        </Element>
        <MouseArea id="MouseArea">
            <FloatPosition>0.000,0.000</FloatPosition>
            <Size>38,38</Size>
            <CursorType>Hand</CursorType>
            <MouseClick id="On">
                <Script>(M:Event) &apos;LeftSingle&apos; scmp 0 ==
      if{
        (L:Derich_enable,bool) ! (&gt;L:Derich_enable,bool)
      }


</Script>
                <ClickType>LeftSingle</ClickType>
            </MouseClick>
        </MouseArea>
        <MouseArea id="MouseArea">
            <FloatPosition>0.000,0.000</FloatPosition>
            <Size>38,38</Size>
            <MouseClick id="Off">
                <Script>(M:Event) &apos;LeftSingle&apos; scmp 0 ==
      if{
        (L:Derich_enable,bool) ! (&gt;L:Derich_enable,bool)
      }
</Script>
            </MouseClick>
        </MouseArea>
    </SimGauge.Gauge>
</SimBase.Document>
 
Last edited:
Hi,

Correct me if I am wrong but I interpret that as (L: Derich_enable,bool) = NOT (L: Derich_enable,bool). So when I click that sets it to not what it was, which based on the 2 case values, limits the output to 1 or 0?

That's correct Sir. Look at it that way:
1. The first (L: Derich_enable,bool) loads the value Derich_enable to the stack
2. The ! operator negates the boolean (true/false) value of the top entry in the stack (which is the value of Derich_enable)
3. The top value in the stack (the negated Derich_enable) is written to Derich_enable with the > (or &gt;) operator.

Of course this just works for boolean values. If you have more complex variable types you need to write some more if{}s or use the case structure (which is very confusing in reverse notation). Search the forum for "fuel selector" to get some examples for that.

Regards
Vitus
 
Hi,



That's correct Sir. Look at it that way:
1. The first (L: Derich_enable,bool) loads the value Derich_enable to the stack
2. The ! operator negates the boolean (true/false) value of the top entry in the stack (which is the value of Derich_enable)
3. The top value in the stack (the negated Derich_enable) is written to Derich_enable with the > (or &gt;) operator.

Of course this just works for boolean values. If you have more complex variable types you need to write some more if{}s or use the case structure (which is very confusing in reverse notation). Search the forum for "fuel selector" to get some examples for that.

Regards
Vitus

Excellent! Thank you so much Vitus. This should help very much. Time to go searching to make the images display as the case changes.
 
Back
Top