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

Push and release button

Zeiten

Resource contributor
Messages
444
Country
norway
Hi.

I'm trying to make a button work so it moves back into position when the mouse is released.

My current code works, I only need to press the button one more time to make it pop back out.

Code:
<PartInfo>
    <Name>oh_rain_rep_co</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:repellent co,number) 50 *
        </Code>
        <Lag>200</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Rain Repellent</TooltipText>
	  <MouseFlags>LeftSingle</MouseFlags>
        <CallbackCode>
         (L:repellent co) ! (&gt;L:repellent co)
        </CallbackCode>
    </MouseRect>
  </PartInfo>

tried with
Code:
<MouseFlags>LeftSingle+Leftrelease</MouseFlags>
<CallbackCode>
(M:Event) 'LeftSingle' scmp 0 ==
if{ 1 (>L:repellent co, enum) }
(M:Event) 'LeftRelease' scmp 0 ==
if{ 0 (>L:repellent co, enum) }
</CallbackCode>

Think I'm on the right track, but not sure.

The code works to some degree.
The hand courser comes up and the tooltip works, but nothing happens when I press the button.

Edit.
Think I had a little aha moment.
Instead of enum it should be bool as enum returns 3 states and bool only 2?

Too bad I cant test it right now:/
 
Last edited:
try something like this
only issue is with the head movement in the vc can cause the mouse cursor to move off the button which will remain on until it sense's the mouse release.
fr Bill has posted some example code here somewhere which fixes this issue by resetting the l:var if it remains on with out the mouse button being held, but I cant find it :)
Code:
	    <MouseRect> 
		<Cursor>Hand</Cursor>
 		<TooltipText>Push to test</TooltipText> 
	   <MouseFlags>LeftSingle+Leftrelease</MouseFlags> 
			<CallbackCode> 
			(L:TEST_right, bool) ! (&gt;L:TEST_right, bool)
		</CallbackCode> 
	</MouseRect>
 
Here is some script I use to animate a push and release button. Note that there are two "release" conditions: LeftRelease and LeftDrag. The latter is included so that if the user's "hand" slips off the button, it will automatically release the switch...

...otherwise it would get stuck in the down position!

nb: the unit used in custom (L:) variables makes no difference at all, it is only useful for human's logic...

Code:
  <PartInfo>
    <Name>B737_GroundCall</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:B737_GroundCall,bool) 50 *
        </Code>
        <Lag>250</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftRelease+LeftDrag</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ 1 (>L:B737_GroundCall,bool) }

        (M:Event) 'LeftRelease' scmp 0 == if{ 0 (>L:B737_GroundCall,bool) }

        (M:Event) 'LeftDrag' scmp 0 == if{ 0 (>L:B737_GroundCall,bool) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>
 
Last edited:
It worked great!

Thanks Bill.

Du er hjertelig velkommen!

As it happens, I have about 300+ such pushbuttons in the B737-200 I'm currently working on! Every "indicator light" has a "push to test light" function, as well as being ganged together to a number of single buttons that will "illuminate" functional groups of such indicator lights...

...which, as you can imagine is a bloody nightmare of "simple" complexity! :yikes: :rotfl:
 
Went to the hairdresser the other day.

She told me I have very thick hair..
It's good thats about to change some time soon :laughing:
 
Here is some script I use to animate a push and release button. Note that there are two "release" conditions: LeftRelease and LeftDrag. The latter is included so that if the user's "hand" slips off the button, it will automatically release the switch...

...otherwise it would get stuck in the down position!

nb: the unit used in custom (L: ) variables makes no difference at all, it is only useful for human's logic...
Bill can that code be used for multiple buttons (i.e. all calling the same code) or would you need to duplicate the code for each button changing the name and L: var in each case?

I have a bunch of buttons I would like to animate but not all would be tied to a FSX function (i.e. some would be 'dummies' that moved but did nothing).
 
If you want each button to be operated seperatly you need to make both the part name and the L:var unique.

This is two examples


Code:
 <PartInfo>
    <Name>oh_rain_rep_co</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:repellent co,number) 50 *
        </Code>
        <Lag>200</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftRelease+LeftDrag</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ 1 (>L:repellent co,bool) }

        (M:Event) 'LeftRelease' scmp 0 == if{ 0 (>L:repellent co,bool) }

        (M:Event) 'LeftDrag' scmp 0 == if{ 0 (>L:repellent co,bool) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>

  
  <PartInfo>
    <Name>oh_rain_washer_cp</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:washer cp,bool) 50 *
        </Code>
        <Lag>300</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftRelease+LeftDrag</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ 1 (>L:washer cp,bool) }

        (M:Event) 'LeftRelease' scmp 0 == if{ 0 (>L:washer cp,bool) }

        (M:Event) 'LeftDrag' scmp 0 == if{ 0 (>L:washer cp,bool) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>

As you can se both codes use the same template, only the names have changed so each button will operate individually.

If you use the same code for all the button, then if you press one they all will move.

You will also need a unique guid for them both.

Code:
<Animation name="oh_rain_rep_co" guid="38ED2605-606E-4333-91C8-76C4076138A1" length="50" type="Sim" typeParam2="oh_rain_rep_co" typeParam="AutoPlay"/>
<Animation name="oh_rain_washer_cp" guid="ABA0ED88-4E4A-4686-A8C5-89CA0B483C4F" length="50" type="Sim" typeParam2="oh_rain_washer_cp" typeParam="AutoPlay"/>
 
As it happens, I have about 300+ such pushbuttons in the B737-200 I'm currently working on! Every "indicator light" has a "push to test light" function, as well as being ganged together to a number of single buttons that will "illuminate" functional groups of such indicator lights...

...which, as you can imagine is a bloody nightmare of "simple" complexity! :yikes: :rotfl:

How about just an "inop" poster? :rotfl::rotfl:
 
That would really look ugly, besides which I doubt any pilot would agree to fly an aircraft with a bunch of DMI or INOP stickers pasted all over the place! :eek:

Just for the same of completeness, here's how you can shorten the script just a tiny bit by combining the two "null" conditions:
Code:
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ 1 (>L:B737_GroundCall,bool) }

        (M:Event) 'LeftRelease' scmp 0 == 
        (M:Event) 'LeftDrag' scmp 0 == or if{ 0 (>L:B737_GroundCall,bool) }
      </CallbackCode>
 
Back
Top