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

FSXA Start-stop-reset button

Messages
189
Country
hungary
Hello

It's me again :) I tried to figure out this code, but sadly I'm not as good porgramer that I want to be, so I ask your help again.

There's a spring loaded button of a analogue clock, which has three function :

1st press : starts the stopwatch
2nd press : stops the stopwatch
3rd press : resets the stopwatch

I think I need an L: variable, which will stepping the value from 0 to 2. It could be enum or number, right ? The anim depends on the value of the L: variable.

I made some code, but all of this are totally wrong so I won't copy it here :)
 
Here is the mouse code for such a switch:

Code:
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Stopwatch</TooltipText>
      <CallbackCode>
        (L:Stopwatch, enum) ++ 3 % (>L:Stopwatch, enum)

        (L:Stopwatch, enum) 1 == if{ //start count// }
        (L:Stopwatch, enum) 2 == if{ //stop count// }
        (L:Stopwatch, enum) 0 == if{ //reset count// }
      </CallbackCode>
    </MouseRect>
 
Thanks Bill, it is what I need :) But I'd like to learn a little bit. What happens "inside" this logic :

Code:
(L:Stopwatch, enum) ++ 3 %

I know that '++' increases the value by 1. '3' acts as a limit of the stepping?
For '%' operator the SDK says 'taking modulo', but as I know modulo is a remainder of a division. What does it mean in your expression?
 
You have it right, you just haven't thought about the results.

If L: variable =, then modulo 3 equals:

1 3 % = 1
2 3 % = 2
3 3 % = 0

Just what we want. :)
 
Thanks for beating me to the punch, Tom. I've been rather busy with misbehaving hardware today and just now check back in.

There are other ways to achieve the same results, but honestly this is by far the simplest to method to use for a push button...

As you can now see, MS/ACES have somewhat "perverted" the normal function of modulo!
 
Now the start-stop-reset knob works the way I want , but the needle of the stopper-seconds stops after one revolution. On this stopwatch one revolution is equal to 30 sec - don't ask way, it is russian :D I picked the codes from SDK and made some modifications to fit to 3D animation. Here is the code for the needle :

Code:
<PartInfo>
    <Name>stopper_mutato_mp</Name>
    <AnimLength>60</AnimLength>
    <Animation>
      <Parameter>
         <Code>
           (L:Running,bool) 1 ==
           if{ (P:Absolute time, seconds) (L:Offset,seconds) - (&gt;L:TotalRunning,seconds) } 
          els{ (P:Absolute time, seconds) (L:TotalRunning,seconds) - (&gt;L:Offset,seconds) } 
          (L:TotalRunning, seconds)
         </Code>
	 </Parameter>
    </Animation>
  </PartInfo>

What's the solution?
 
I used my own brain a little :D

Code:
(L:TotalRunning, seconds) flr 60 %

Cheers ;)
 
Last edited:
I used my own brain a little :D

Code:
(L:TotalRunning, seconds) flr 60 %

Cheers ;)

Bingo! See, the example of using the modulo function to reset the button provided the answer for resetting the seconds hand of the stop watch!
 
Great thread!
I made something similar last year for my Bf108, but I had to move a couple of items into a 2d gauge because I obviously had my head in my arse.
This made me rethink a few points and here is what is working for me in full 3d. :-)
As a little bonus there's a tooltip showing state of the button and the elapsed time. Quite handy I think because round instruments are not always very well readable.
One oddity, I had to move the reset code to the needle animation because it didn't "catch" when located in the button's callback code.
There's two needles btw, the usual seconds needle and another one making 15 minutes per revolution.
Don't ask, German tech. :-)
First one is the button

EDIT: Ignore the "1 (&gt;L:XMLSND2,enum" part, this is a sound played using Bill's module.

Code:
<PartInfo>
     <Name>bf108_stoppuhr_schalter</Name>
     <AnimLength>75</AnimLength>
     <Animation>
        <Parameter>
        <Code> 
        (L:bf108stoppschalter,number) 25 *
        </Code>  
        </Parameter>
     </Animation>
         <MouseRect> 
           <Cursor>Hand</Cursor> 
           <TooltipText>
                      <String>%((L:bf108stoppschalter,number))
                     %{case}
                         %{:0} Stop Watch: Off
                         %{:1} Stop Watch: Running (%((L:TotalRunning1,MINUTES) flr 60 %)%!02d!:%((L:TotalRunning1,SECONDS) flr 60 %)%!02d!)
                         %{:2} Stop Watch: Hold at (%((L:TotalRunning1,MINUTES) flr 60 %)%!02d!:%((L:TotalRunning1,SECONDS) flr 60 %)%!02d!)
                         %{:3} Stop Watch: Reset
                     %{end}
                   </String>
                   </TooltipText> 
             <MouseFlags>LeftSingle</MouseFlags> 
           <CallbackCode>                  
     (M:Event) 'LeftSingle' scmp 0 ==   
          if{ (L:bf108stoppschalter, number) ++ 3 min (&gt;L:bf108stoppschalter, number) 1 (&gt;L:XMLSND2,enum) } 
                (L:bf108stoppschalter,number) 1 == if{ (L:Running1,bool) ! (&gt;L:Running1,bool) } 
                (L:bf108stoppschalter,number) 2 == if{ 0 (&gt;L:Running1,bool) } 
                (L:bf108stoppschalter,number) 3 == if{ 0 (&gt;L:bf108stoppschalter,number) }     
           </CallbackCode>
     </MouseRect> 
   </PartInfo>

The seconds needle holding the reset code and the actual time calculations


Code:
<PartInfo> 
        <Name>bf108_stoppuhr_sekunden</Name>
         <AnimLength>60</AnimLength>
        <Animation> 
            <Parameter> 
                    <Code> 
                    (L:bf108stoppschalter,number) 0 == if{ 0 (&gt;L:TotalRunning1,seconds) 0 (&gt;L:Running1,bool) }
                    (L:Running1, bool) ! if{ (P:Absolute time, seconds) (&gt;L:Offset1, seconds) }  
                    (L:Running1,bool) if{ (P:Absolute time, seconds) (L:Offset1,seconds) - (&gt;L:TotalRunning1,seconds) } 
                      els{ (P:Absolute time, seconds) (L:TotalRunning1,seconds) - (&gt;L:Offset1,seconds) }
                    (L:TotalRunning1,seconds) flr 60 %
                   </Code> 
            </Parameter> 
        </Animation> 
    </PartInfo>

The 15-minutes-per-revolution needle.
Could be made easier with less keyframes if set to minutes rather than seconds I guess.

Code:
<PartInfo> 
        <Name>bf108_stoppuhr_minuten</Name>
         <AnimLength>900</AnimLength>
        <Animation> 
            <Parameter> 
                    <Code>
                    (L:TotalRunning1,seconds) flr 900 %
                   </Code> 
            </Parameter> 
        </Animation> 
    </PartInfo>
 
Last edited:
For the next question I made a screenshot. You can see that there is one more clock for the flight time counting in hours/minutes. I made the code from the stopwatch's code with different variables. The problem is that when I push the stopwatch knob, the flight time knob is also animated and the flight time won't start. What did I wrong?

attachment.php


The code for stopwatch knob :

Code:
<PartInfo>
    <Name>stopper_gomb</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:stopper_gomb,bool) (P:local time,seconds) &gt; if{ 50 } els{ 0 }</Code>
       </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Stopwatch</TooltipText>
      <CallbackCode>
        (L:Stopwatch,enum) ++ 3 % (>L:Stopwatch,enum)
        (P:local time,seconds) 0.25 + (>L:stopper_gomb,bool)
       
        (L:Stopwatch, enum) 1 == if{ 1 (>L:Running,bool) (P:Absolute time, seconds) (&gt;L:Offset, seconds) } 
        (L:Stopwatch, enum) 2 == if{ 0 (>L:Running,bool) 0 (&gt;L:Offset, seconds) }  
        (L:Stopwatch, enum) 0 == if{ 0 (>L:TotalRunning,seconds) }                                
      </CallbackCode>
    </MouseRect>
  </PartInfo>

and for the flight time knob :

Code:
<PartInfo>
    <Name>repido_gomb</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:repido_gomb,bool) (P:local time,seconds) &gt; if{ 50 } els{ 0 }</Code>
       </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Flight time</TooltipText>
      <CallbackCode>
        (L:repido,enum) ++ 3 % (>L:repido,enum)
        (P:local time,seconds) 0.25 + (>L:repido_gomb,bool)
        (L:repido, enum) 1 == if{ 1 (>L:repidomegy,bool) (P:Absolute time, seconds) (&gt;L:valami, seconds) } 
  (L:repido, enum) 2 == if{ 0 (>L:repidomegy,bool) 0 (&gt;L:valami, seconds) }  
       (L:repido, enum) 0 == if{ 0 (>L:repidoTotalRunning,seconds) }   

       </CallbackCode>
    </MouseRect>
  </PartInfo>
 

Attachments

  • óra.JPG
    óra.JPG
    86.7 KB · Views: 933
Gaspen, I believe the time calculation don't work in the callback code.
At least that what initially bummed me and forced me to port most of the code into a 2d gauge.
Probably better to move that section into the code of the flight time needle?
 
Then anim and function of "stopper_gomb" and stopwatch needles works good. The problem is only with the flight time knob and needles.
 
Continuous calculations will only run in a <Code> section.

The easiest solution is to create a tiny polygon in your project to which you can assign a <Visibility> condition...

...then use that as a place to add all of your project's "continuous calculations" scripts. The reason why this works of course is that the sim will always be evaluating what is inbetween the <Code>...</Code> tags whether the polygon is visible or not!

For example, this is what I use to initialize some things when the aircraft is first loaded, and where the continuous calculation for (L:TotalFuel,enum) is done.

Code:
  <PartInfo>
    <Name>f86_Logic</Name>
    <Visibility>
      <Parameter>
        <Code>
          (L:F86_init,bool) 0 ==
          if{
          1 (>K:SMOKE_TOGGLE)
          (>K:STROBES_OFF)
          1 (>L:F86_init,bool)
          }

          <!-- TOTAL MAIN FUEL WEIGHT -->
          (A:FUEL TOTAL QUANTITY WEIGHT,Pounds)
          (A:FUEL TANK EXTERNAL1 QUANTITY, Gallons) (A:FUEL WEIGHT PER GALLON, Pounds) * -
          (A:FUEL TANK EXTERNAL2 QUANTITY, Gallons) (A:FUEL WEIGHT PER GALLON, Pounds) * -
          (>L:TotalFuel,enum)
        </Code>
      </Parameter>
    </Visibility>
  </PartInfo>
 
Thanks Bill ! Today - while I was waiting some posts here :) - I cleaned my codes, I put the calculations into the needle's code instead, as Mathias said. Now the counting of the stopwatch and the flight time is separated. Left button stops/starts/resets the stopwatch, and the right one does the same with the flight time needles. It is okay now.

Only one error remained : the right button is moving only when I push the left button, but when I push the right itself it doesn't move :confused:
 
Mathias !

I used your code to display tooltip text by the state of the button, but the text field is too long. How can I shorten it?

Code:
 <TooltipText>
           <String>%((A:GENERAL ENG MASTER ALTERNATOR:1, bool))%
                 %{case}
                 %{:0} Generator (off)
                 %{:1} Generator (on)
                 %{end}
           </String>
          </TooltipText>

attachment.php
 
Tooltip text is as long or as short as you desire.
This is a code snippet from my emergency oxygen "PULL" knob.
The red bits are the actual texts.
vololiberista
Code:
 <Tooltip>[COLOR="Red"]Emergency Oxygen [/COLOR]%( (L:redpull,bool) )%{if}[COLOR="Red"]Out (Press to Reset)[/COLOR]%{else}%( (L:redpush,bool) )%{if}[COLOR="Red"]Test (hold for 5 secs)[/COLOR]%{else}[COLOR="Red"]In (Press to Test)[/COLOR]%{end}</Tooltip>
 
Back
Top