• 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 Toggle switch script question

Messages
52
Country
unitedstates
I've modified this script to operate the toggle switch for the oil cooler.
I've managed to get the switch to start at it's center position and move forward
to open the cooler but I can't get it to spring back to the center position when I release
the mouse button. Also when I move the mouse back it closes the cooler but the switch's back animation
is not present. I would also like it to spring back to the center position once I release the mouse button
after the oil cooler is closed. Idealy it would be nice to have the cooler open and close in increments but
I'll be happy if the switch operates properly.

Code:
<PartInfo>
    <Name>lever_oil_cooler</Name>
    <AnimLength>100</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:lever_oil_cooler, bool) 50 * 50 + </Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftDrag+LeftSingle+MoveRepeat+LeftRelease</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle'  scmi 0 == if{ (M:X) (&gt;L:ClickStart) }
        (M:Event) 'LeftRelease' scmi 0 == if{ 50 (&gt;L:lever_oil_cooler, bool) 100}
        (M:Event) 'LeftDrag'    scmi 0 == if{ (M:X) (L:ClickStart) - 0 &lt;
        if{ (&gt;L:lever_oil_cooler, bool) 0 -1 (&gt;L:oil_cooler, bool) quit }
        els{ (&gt;L:lever_oil_cooler, bool) 0 1 (&gt;L:oil_cooler, bool) quit } }
      </CallbackCode>
    </MouseRect>
  </PartInfo>
As always any help is appreciated.
 
There is no unit defined in (L:ClickStart) or (&gt;L:ClickStart).
Try (L:ClickStart,number)

Ted.
 
Thanks Ted for your suggestion. I tried it but unfortunately it had no effect.
With the following changes I get the full switch animation. Forward mouse movement opens the cooler and the switch springs back to the start position and can then be pulled back to the close position and springs back to the start position once released, however the cooler will not close now. I feel this is 2 steps forward with 1 step back so I'm making progress. I'll keep trying.

Code:
<PartInfo>
    <Name>lever_oil_cooler</Name>
    <AnimLength>100</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:lever_oil_cooler, bool) 50 * 50 + </Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftDrag+LeftSingle+MoveRepeat+LeftRelease</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle'  scmi 0 == if{ (M:X) (&gt;L:ClickStart,) }
        (M:Event) 'LeftRelease' scmi 0 == if{ 0 (&gt;L:lever_oil_cooler, bool) }
        (M:Event) 'LeftDrag'    scmi 0 == if{ (M:X) (L:ClickStart,) - 0 &lt;
        if{ (&gt;L:lever_oil_cooler, bool) -1 (&gt;L:lever_oil_cooler, bool) }
        els{ (&gt;L:lever_oil_cooler, bool) 1 (&gt;L:lever_oil_cooler, bool) }
        if{ (&gt;L:oil_cooler, bool) 0 -1 (&gt;L:oil_cooler, bool) }
        els{ (&gt;L:oil_cooler, bool) 0 1 (&gt;L:oil_cooler, bool) } }
      </CallbackCode>
    </MouseRect>
  </PartInfo>
 
Thanks Ted for your suggestion. I tried it but unfortunately it had no effect.

Um, no you did not!

(&gt;L:ClickStart) will NEVER work!

All L:variables must have a "unit" assigned. One of the following three forms:

Code:
(&gt;L:ClickStart,enum)
(&gt;L:ClickStart,number)
(&gt;L:ClickStart,bool)
 
Last edited:
I had forgotten about that post. Thanks for bringing it back to my attention.

I've created a new two part post with the formatting corrected, and put it in the Tutorials forum at Freeflight Design:

http://www.aerodynamika.com/cgi-bin/yabb2/YaBB.pl?num=1297743860/0#0
Np I dont know what Id do if Freeflight Design went away its kinda my private uh oh data base :)
Pitty the search engine has been reduced to 15 matchs,I think its getting quite large as a few times it has timed out on searches in the main message area
Wozza
 
Hi
This any help?

Thank you Au-MaV. It was very helpfull. With quite a bit of trial and error the following script is what I came up with and both the switch and cooler door are working perfectly.

Code:
<PartInfo>
    <Name>lever_oil_cooler</Name>
    <AnimLength>100</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:lever_oil_cooler, bool) 50 * 50 + </Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle+LeftRelease+LeftDrag</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle'  scmi 0 == if{ (M:X) (&gt;L:ClickStart,) }
        (M:Event) 'LeftRelease' scmi 0 == if{ 0 (&gt;L:lever_oil_cooler, bool) }
        (M:Event) 'LeftDrag'    scmi 0 == if{ (M:X) (L:ClickStart,) &lt; if{ -1 (&gt;L:lever_oil_cooler, bool) -1 (&gt;L:oil_cooler, bool) }
              els{ 1 (&gt;L:lever_oil_cooler, bool) 1 (&gt;L:oil_cooler, bool) }  
      </CallbackCode>
    </MouseRect>
  </PartInfo>

Um, no you did not!

(&gt;L:ClickStart,) will NEVER work!

All L:variables must have a "unit" assigned. One of the following three forms:

Yes I did try it. In my original script it had no effect. Just out of curiousity I tried (&gt;L:ClickStart,number) in the new script as well and again it had no effect.
I'm barely a novice at scripting and have no motivation not to try suggestions that are offered. I believe that the purpose of the (&gt;L:ClickStart,) without an assigned unit is to grab the part without moving it.
I tried the new script without (M:Event) 'LeftSingle' scmi 0 == if{ (M:X)(&gt;L:ClickStart,) } and the switch would jump forward to the final frame of the animation and eliminated the ability to drag it back to the first frame.
As always all the help and suggestions I have recieved and hopefully will recieve in the future are greatly appreciated.
 
Last edited:
Np I dont know what Id do if Freeflight Design went away its kinda my private uh oh data base :)
Pitty the search engine has been reduced to 15 matchs,I think its getting quite large as a few times it has timed out on searches in the main message area
Wozza

Will see what can be done about that.
 
Yes I did try it. In my original script it had no effect. Just out of curiousity I tried (L:ClickStart,number) in the new script as well and again it had no effect.

Here is the relevant quote from the FSX SDK:

Local Parameters (L:)
When a local parameter is first referenced, it is created and its value is set to zero. Use your own names for these parameters, but care should be taken that these names are unique. Use unit names when referencing them, for example:

(L:Stopwatch Toggle Position, bool)

Having gone back and reviewed the original post, I note that you had left out the comma:
(&gt;L:ClickStart)

In your latest example, you added a comma to the expression:
(&gt;L:ClickStart,)

As it happens, just adding the comma "works" because absent a definite unit definition, FSX "assumes" a boolean (bool) unit type. This is not however a good practice.

The reason it's not a "good practice" is simply because you can have two L:vars with the same root name, but entirely different units, effectively having two entirely unique variables! In fact, you can actually create more than two unique variables:
Code:
(L:RunningTime,bool)
(L:RunningTime,seconds)
(L:RunningTime,number)

Let's examine just what your (L:var,) is actually doing:

In the event LeftClick, (&gt;L:ClickStart,) sets the variable to TRUE (e.g., 1)

In the event LeftDrag, the expression (L:ClickStart,) &lt; if{ ... } els{ ... } means "if (L:ClickStart,) is FALSE, then { do this }, els { do that }

Effectively however, only the "els" can ever be executed, since it's not possible for LeftDrag to ever be TRUE at the same time that (L:ClickStart,) is FALSE...

...because LeftDrag can never be TRUE unless LeftClick is also TRUE!
 
Last edited:
Back
Top