• 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.

FSX Multiple source for Select Case - SOLVED

Messages
35
Country
ca-quebec
Soliution: http://www.fsdeveloper.com/forum/threads/multiple-source-for-select-case-solved.438980/#post-760726


Hi,

Essentially, I'm trying to use varying sources for Value in my Select Case:

Code:
If
  test1 is not 0, use test1
else
  If
    test2 is not 0, use test2
  else
    use line1

I've read many threads on scripting and came up with this:

Code:
         <Value>
           (L:KKX_MipButAutolandTest1) 0 !=
           if{
             (L:KKX_MipButAutolandTest1, number)
           }else{
             (L:KKX_MipButAutolandTest2) 0 !=
             if{
               (L:KKX_MipButAutolandTest2, number)
             }else{
               (L:KKX_MipAnnAutolandLine1, number)
             }end
           }end
         </Value>

But it only works for Test1, Test2 and Line1 never fall through.

Thanks!

Robert
 
Last edited:
Code:
         <Value>
           (L:KKX_MipButAutolandTest1,number) 0 !=
           if{
            (L:KKX_MipButAutolandTest1,number)
            }
         els{
            (L:KKX_MipButAutolandTest2,number) 0 !=
            if{
              (L:KKX_MipButAutolandTest2,number)
              }
           els{
              (L:KKX_MipAnnAutolandLine1,number)
              }
            }
         </Value>

Hopefully this works.

Maybe you should post more of your code??
 
Last edited:
Slightly different without if/else's.

Test1, Test2
0, 0 <-- Use Line1
1, 0 <-- Use Test1
0, 1 <-- Use Test2
1, 1 <-- Most likely invalid

Code:
<Value>
        (L:KKX_MipButAutolandTest1) 0 ==  (L:KKX_MipButAutolandTest2) 0 == and if{ (L:KKX_MipAnnAutolandLine1, number) }
        (L:KKX_MipButAutolandTest1) 0 !=  (L:KKX_MipButAutolandTest2) 0 == and if{ (L:KKX_MipButAutolandTest1, number) }
        (L:KKX_MipButAutolandTest1) 0 ==  (L:KKX_MipButAutolandTest2) 0 != and if{ (L:KKX_MipButAutolandTest2, number) }
</Value>

or

Code:
<Value>
        (L:KKX_MipButAutolandTest1) sp1 0 ==  (L:KKX_MipButAutolandTest2) sp2 0 == and if{ (L:KKX_MipAnnAutolandLine1, number) }
        l1 0 !=  l2 0 == and if{ (L:KKX_MipButAutolandTest1, number) }
        l10 ==  l2 0 != and if{ (L:KKX_MipButAutolandTest2, number) }
</Value>
 
... Maybe you should post more of your code??

Usually I post my entire program, I even post pics in my previous posts. But I posted the bare essentials in this one 'cause I thought it was just purely a syntax question (but I've been wrong before).
 
Roman,

Yes, only one Test button will be pressed. If both are pressed, I still only process one.

I really liked the structure of your first IF but it behaves similar to mine; Line1 and Line2 are ignored, Test1 works fine, Test2 processes as if Test1.

I don't quite understand what's going on in the second IF. Is there a syntax error on the last line? (missing a space after l1)

l10 == l2 0 != and if{ (L:KKX_MipButAutolandTest2, number) }







I am redoing as many gauges as I can in the Level-D 767. My eyes are getting old and weak.
 
I mapped two buttons on my CH controller for testing purposes; Press with param 1, Release with Param 0:

FSUIPC.INI
...
[LuaFiles]
1=ipcinit
2=ipcready
3=KKCtrFlaps
4=KKmain
5=KKAutoland
6=KKAutoland1
7=KKAutoland2

[Buttons.LVLD_B763]
0=P1,0,CL6:R,1 -{Lua KKAutoland1}-
1=U1,0,CL6:R,0 -{Lua KKAutoland1}-
2=P1,1,CL7:R,1 -{Lua KKAutoland2}-
3=U1,1,CL7:R,0 -{Lua KKAutoland2}-


KKAutoland1.lua:

ipc.writeLvar("L:KKX_MipButAutolandTest1",ipcPARAM)


KKAutoland2.lua:

ipc.writeLvar("L:KKX_MipButAutolandTest2",ipcPARAM)


Button 1 is pressed and released (KKAutoland1.log):

********* LUA: "KKAutoland1" Log [from FSUIPC version 4.958] *********
329312 System time = 20/12/2016 09:14:56, Simulator time = 09:14:36 (13:14Z)
329312 LUA: beginning "E:\Steam\steamapps\common\FSX\Modules\KKAutoland1.lua"
329312 LUA: ...:\Steam\steamapps\common\FSX\Modules\KKAutoland1.lua:1
329312 LUA: Global: ipcPARAM = 1
329328 LUA: ended "E:\Steam\steamapps\common\FSX\Modules\KKAutoland1.lua"
329328 System time = 20/12/2016 09:14:56, Simulator time = 09:14:36 (13:14Z)
********* LUA execution terminated: Log Closed *********

********* LUA: "KKAutoland1" Log [from FSUIPC version 4.958] *********
333750 System time = 20/12/2016 09:15:01, Simulator time = 09:14:41 (13:14Z)
333750 LUA: beginning "E:\Steam\steamapps\common\FSX\Modules\KKAutoland1.lua"
333750 LUA: ...:\Steam\steamapps\common\FSX\Modules\KKAutoland1.lua:1
333750 LUA: Global: ipcPARAM = 0
333781 LUA: ended "E:\Steam\steamapps\common\FSX\Modules\KKAutoland1.lua"
333781 System time = 20/12/2016 09:15:01, Simulator time = 09:14:41 (13:14Z)
********* LUA execution terminated: Log Closed *********


Button 2 is pressed and released (KKAutoland2.log):

********* LUA: "KKAutoland2" Log [from FSUIPC version 4.958] *********
557125 System time = 20/12/2016 09:18:44, Simulator time = 09:18:24 (13:18Z)
557125 LUA: beginning "E:\Steam\steamapps\common\FSX\Modules\KKAutoland2.lua"
557125 LUA: ...:\Steam\steamapps\common\FSX\Modules\KKAutoland2.lua:1
557125 LUA: Global: ipcPARAM = 1
557140 LUA: ended "E:\Steam\steamapps\common\FSX\Modules\KKAutoland2.lua"
557140 System time = 20/12/2016 09:18:44, Simulator time = 09:18:24 (13:18Z)
********* LUA execution terminated: Log Closed *********

********* LUA: "KKAutoland2" Log [from FSUIPC version 4.958] *********
561171 System time = 20/12/2016 09:18:48, Simulator time = 09:18:28 (13:18Z)
561171 LUA: beginning "E:\Steam\steamapps\common\FSX\Modules\KKAutoland2.lua"
561171 LUA: ...:\Steam\steamapps\common\FSX\Modules\KKAutoland2.lua:1
561171 LUA: Global: ipcPARAM = 0
561187 LUA: ended "E:\Steam\steamapps\common\FSX\Modules\KKAutoland2.lua"
561187 System time = 20/12/2016 09:18:48, Simulator time = 09:18:28 (13:18Z)
********* LUA execution terminated: Log Closed *********

I'm going to try your second IF even if I don't understand it yet.

Robert
 
Autoland XML gauge:

Code:
<Gauge Name="Autoland" Version="1.0">
  <Image Name="MipAnnAutolandBkgd.bmp"/>

    <!-- ==================== Line 1 ==================== -->

  <Element>
    <Position X="1" Y="1"/>
      <Select>
         <Value>
           (L:KKX_MipButAutolandTest1) 0 == (L:KKX_MipButAutolandTest2) 0 == and
             if{ (L:KKX_MipAnnAutolandLine1, number) }
           (L:KKX_MipButAutolandTest1) 0 != (L:KKX_MipButAutolandTest2) 0 == and
             if{ (L:KKX_MipButAutolandTest1, number) }
           (L:KKX_MipButAutolandTest1) 0 == (L:KKX_MipButAutolandTest2) 0 != and
             if{ (L:KKX_MipButAutolandTest2, number) }
         </Value>
         <Case Value="0">
           <Image Name="MipAnnAutolandOff.bmp" Bright="No"/>
         </Case>
         <Case Value="1">
           <Image Name="MipAnnAutolandLand3.bmp" Bright="Yes"/>
         </Case>
         <Case Value="2">
           <Image Name="MipAnnAutolandLand2.bmp" Bright="Yes"/>
         </Case>
      </Select>
  </Element>

    <!-- ==================== Line 2 ==================== -->

  <Element>
    <Position X="1" Y="42"/>
      <Select>
         <Value>
           (L:KKX_MipButAutolandTest1) 0 == (L:KKX_MipButAutolandTest2) 0 == and
             if{ (L:KKX_MipAnnAutolandLine2, number) }     CORRECTED, Line1 --> Line2, No Autoland now displayed, still not processing Test2
           (L:KKX_MipButAutolandTest1) 0 != (L:KKX_MipButAutolandTest2) 0 == and
             if{ (L:KKX_MipButAutolandTest1, number) }
           (L:KKX_MipButAutolandTest1) 0 == (L:KKX_MipButAutolandTest2) 0 != and
             if{ (L:KKX_MipButAutolandTest2, number) }
         </Value>
         <Case Value="0">
           <Image Name="MipAnnAutolandOff.bmp" Bright="No"/>
         </Case>
         <Case Value="1">
           <Image Name="MipAnnAutolandNoLand3.bmp" Bright="Yes"/>
         </Case>
         <Case Value="2">
           <Image Name="MipAnnAutolandNoAutoland.bmp" Bright="Yes"/>
         </Case>
      </Select>
  </Element>
</Gauge>
 
Last edited:
I use Lekseecon FSUIPC version to get access to Level-D 767 offsets. This is where the two indicators on the gauge are determined (Line1 and Line2). Test buttons 1 and 2 are used to override these indicators temporarily. Once released, the indicators revert to this state.

Autoland.lua:

Code:
--  AUTOLAND STATUS
--    lekseecon = 856       0=off, 1=on
--    fsuipc    = 0x9358    1 byte, type UB
--      No autoland           bit 0
--      No land 3             bit 1
--      Land 2                bit 2
--      Land 3                bit 3

while 1 do

  MipAnnAutolandNoAutoland_in = 0
  MipAnnAutolandNoLand3_in = 0
  MipAnnAutolandLand2_in = 0
  MipAnnAutolandLand3_in = 0

  MipAnnAutolandLine1 = 0
  MipAnnAutolandLine2 = 0

  if ipc.readUB(0x9358) == nil then
    MipAnnAutolandNoAutoland_in = 0
    MipAnnAutolandNoLand3_in = 0
    MipAnnAutolandLand2_in = 0
    MipAnnAutolandLand3_in = 0
  else

    if logic.And(ipc.readUB(0x9358),1) ~= 0 then
      MipAnnAutolandNoAutoland_in = 1
      MipAnnAutoLandLine2 = 2
    end

    if logic.And(ipc.readUB(0x9358),2) ~= 0 then
      MipAnnAutolandNoLand3_in = 1
      MipAnnAutoLandLine1 = 2
    end

    if logic.And(ipc.readUB(0x9358),4) ~= 0 then
      MipAnnAutolandLand2_in = 1
      MipAnnAutoLandLine2 = 1
    end

    if logic.And(ipc.readUB(0x9358),8) ~= 0 then
      MipAnnAutolandLand3_in = 1
      MipAnnAutoLandLine1 = 1
    end
  end

--  ipc.writeLvar("L:KK_MipAnnAutolandNoAutoland", MipAnnAutolandNoAutoland_in)
--  ipc.writeLvar("L:KK_MipAnnAutolandNoLand3", MipAnnAutolandNoLand3_in)
--  ipc.writeLvar("L:KK_MipAnnAutolandLand2", MipAnnAutoLandLand2_in)
--  ipc.writeLvar("L:KK_MipAnnAutolandLand3", MipAnnAutolandLand3_in)

  ipc.writeLvar("L:KKX_MipAnnAutolandLine1", MipAnnAutolandLine1)
  ipc.writeLvar("L:KKX_MipAnnAutolandLine2", MipAnnAutoLandLine2)
end
 
I don't quite understand what's going on in the second IF. Is there a syntax error on the last line? (missing a space after l1)

OOPS! Not enough coffee!
l10 == should be l1 0 == corrected here -
Code:
<Value>
        (L:KKX_MipButAutolandTest1) sp1 0 ==  (L:KKX_MipButAutolandTest2) sp2 0 == and if{ (L:KKX_MipAnnAutolandLine1, number) }
        l1 0 !=  l2 0 == and if{ (L:KKX_MipButAutolandTest1, number) }
        l1 0 ==  l2 0 != and if{ (L:KKX_MipButAutolandTest2, number) }
</Value>
 
Just got back from errands.

Ooops, I messed up too.

LINE 2 logic in my gauge XML used Line1 as source for Value, now replaced with Line2. No Autoland now appears as it should when no buttons are pressed.

But I still get logic for Test1 if I press either button, Test2 still does not get picked up. I must still have a silly syntax error 'cause now both Line1 and Test1 get processed properly.

Making progress. :)
 
Last edited:
Or not...

Tried a bunch of variations of Roman's ideas, none worked as desired.

I noticed he brought in the concept of stack, most likely to make sure nothing gets in the way of the final result.

This structure processes Line1 when Test1 and Test2 are NOT pressed, as desired: (edit)

Code:
         <Value>
           (L:KKX_MipButAutolandTest1) != 0
           if{ (L:KKX_MipButAutolandTest1, number) }

             els{ (L:KKX_MipButAutolandTest2) != 0 }
             if{ (L:KKX_MipButAutolandTest2, number) }

               els{ (L:KKX_MipAnnAutolandLine1, number) }
         </Value>

Line1 is the last option and it works, so it's not a matter of "stuff" staying stuck on top of the stack (that I can tell).

But now Test1 and Test2 are considered as 0 when pressed.

Out of ideas, going to grab a bite.
 
Last edited:
Remove the red char and add the blue one:

els{ (L:KKX_MipButAutolandTest2) != 0 }
if{ (L:KKX_MipButAutolandTest2, number) }
els{ (L:KKX_MipAnnAutolandLine1, number) }
}

Tom
 
Nope. Line1 (and Line2, keeping code simple to illustrate) get processed when no buttons are pressed. Pressing Test1 or Test2 and they are treated as = 0, param 1 is overwritten/lost-in-space.

(I'm a visual person so I really like the idea of splitting the lines to help distinguish what does what)

Code:
         <Value>
           (L:KKX_MipButAutolandTest1) != 0
           if{ (L:KKX_MipButAutolandTest1, number) }

           els{ (L:KKX_MipButAutolandTest2) != 0
             if{ (L:KKX_MipButAutolandTest2, number) }

             els{ (L:KKX_MipAnnAutolandLine1, number) }
              }
         </Value>
 
I can give you a logic that must work as per your pictures:

Code:
  <Element>
    <Position X="1" Y="1"/>
      <Select>
         <Value>
            0         // Autoland OFF by default
            (L:KKX_MipButAutolandTest1) 0 !=
            if{ p 1 } // Land3
            (L:KKX_MipButAutolandTest2) 0 !=
            if{ p 2 } // Land2 
         </Value>
         <Case Value="0">
           <Image Name="MipAnnAutolandOff.bmp" Bright="No"/>
         </Case>
         <Case Value="1">
           <Image Name="MipAnnAutolandLand3.bmp" Bright="Yes"/>
         </Case>
         <Case Value="2">
           <Image Name="MipAnnAutolandLand2.bmp" Bright="Yes"/>
         </Case>
      </Select>
  </Element>

    <!-- ==================== Line 2 ==================== -->

  <Element>
    <Position X="1" Y="42"/>
      <Select>
         <Value>
            2         // No Autoland by default
            (L:KKX_MipButAutolandTest1) 0 !=
            if{ p 1 } // No Land3
            (L:KKX_MipButAutolandTest2) 0 !=
            if{ p 2 } // No Autoland 
         </Value>
         <Case Value="0">
           <Image Name="MipAnnAutolandOff.bmp" Bright="No"/>
         </Case>
         <Case Value="1">
           <Image Name="MipAnnAutolandNoLand3.bmp" Bright="Yes"/>
         </Case>
         <Case Value="2">
           <Image Name="MipAnnAutolandNoAutoland.bmp" Bright="Yes"/>
         </Case>
      </Select>
  </Element>

I am only considerig the basic status (no tests); test1 and test2 situations. I guess Autoland's normal operations would be managed throug Line1/Line2 vars, so you can adapt this example accordingly.
There is no need to check for both Test1 AND test2 in a single line, as they are mutual excluyent ( it is not logical to press both buttons at the same time )

Tom
 
...
I am only considerig the basic status (no tests); test1 and test2 situations. I guess Autoland's normal operations would be managed throug Line1/Line2 vars, so you can adapt this example accordingly.
...

That's a huge part of my problem, Line1/Line2 arrive at the gauge pre-set. And I'm having a hard time getting scripts to behave according to my dreams.

So I simplified things. The gauge now reads LVARs Line1/Line2, nothing else, no test buttons. I've tested it with hard-coded values and all combinations work so that eliminates XML from the debug equation.

I check the test buttons in the LUA script where I determine Line1/Line2, and override at the bottom if necessary.

Variables for buttons Test1/Test1 are no longer LVARs since they are used exclusively within LUA. I now use SET and GET for those.

And it works!

(I didn't do the finger acrobatics this time to click the test buttons on the original gauge with the mouse, press the button on my controller and take a screen print.)






The dumb part is that's what I tried first, but never got it to work so I tried to override at the XML end. Learning both LUA, XML and now scripting proved too much for my brain as flexible as a 2x4. So I come back to override at the LUA end and get it working first shot.

Thank you all for the help with scripting. I'll forget most, but my thread will serve as a reference for me. I know I'm going to have to touch it eventually on another gauge. Right now I just wanted the darn Autoland gauge working, it looked so simple; it's been over 4 days now trying to get this figured out.


Now if I can just figure out how to get it to work with just a flick of the button on the CH thuster quadrant. I have to press the button for nearly a second of else I lose the Release action and Parameter 0 never gets sent (turning off Test1).


Robert
 
Last edited:
Back
Top