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

More visible conditional questions

Zeiten

Resource contributor
Messages
444
Country
norway
Hi guys!

Just wondering about something (as usually)

Lets say I want to have an switch that turn on an light and another one to turn it off again.

How do you script that?

Both buttons are press and release buttons so the light turn off again as soon as the button pops back out.

How do you script the light to still light up until the other button is pressed?
:confused:
 
Make three variables - the two buttons and the light. That way they can all operate independently.

Hope this helps,
 
But I'm really not sure how to script that.

Came up with this code and it sort of works the way I was planning.
The evac button will not move back out again until the horncutout switch is pressed and then again turn the evac light off again.

Code:
    <PartInfo>
    <Name>oh_evac_signal_horncut_switch</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:oh evac signal cutout,bool) 50 *
        </Code>
        <Lag>300</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Evac Signal Horn Cutout</TooltipText>
	  <MouseFlags>LeftSingle+LeftRelease+LeftDrag</MouseFlags>
        <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ 1 (>L:oh evac signal cutout,bool) 0 (>L:oh evac signal command,bool) }

        (M:Event) 'LeftRelease' scmp 0 == 
        (M:Event) 'LeftDrag' scmp 0 == or if{ 0 (>L:oh evac signal cutout,bool) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>
  
      <PartInfo>
    <Name>oh_evac_signal_command</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:oh evac signal command,bool) 50 *
        </Code>
        <Lag>300</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Command Evac Signal</TooltipText>
	  <MouseFlags>LeftSingle</MouseFlags>
        <CallbackCode>
       <CallbackCode>
        ! (&gt;L:oh evac signal command,bool)
        </CallbackCode>
      </CallbackCode>
    </MouseRect>
  </PartInfo>
  
   <PartInfo>
        <Name>oh_evac_invisible</Name>
        <AnimLength>50</AnimLength>
        <Visibility>
            <Parameter>
        	<Code>
			(A:ELECTRICAL MASTER BATTERY, bool)
			(L:oh evac signal command,bool) and 1 == 
			if{ 0 } els{ 1 }
			 </Code>
            </Parameter>
        </Visibility>
    </PartInfo>
	
   <PartInfo>
        <Name>oh_evac_visible</Name>
        <AnimLength>50</AnimLength>
        <Visibility>
            <Parameter>
        	<Code>
        	(A:ELECTRICAL MASTER BATTERY,bool) 0 !=
			if{
			(L:oh evac signal command,bool) 1 == if{ 1 } els{ 0 }
	        </Code>
            </Parameter>
        </Visibility>
    </PartInfo>

But the thing I want is that the evac button will spring back into place without the light go back off.
 
In your second mouse tag you have:

Code:
! (&gt;L:oh evac signal command,bool)

Should be:

Code:
(L:oh evac signal command,bool) ! (&gt;L:oh evac signal command,bool)

Your visibility tags dont need the Animation length line and in the first one you have:

Code:
(A:ELECTRICAL MASTER BATTERY, bool)
 (L:oh evac signal command,bool) and 1 == 
  if{ 0 } els{ 1 }

when all you need is:

Code:
(A:ELECTRICAL MASTER BATTERY, bool)
 (L:oh evac signal command,bool) and
  if{ 0 } els{ 1 }

As for your second viz tag, you are missing a }:

Code:
(A:ELECTRICAL MASTER BATTERY,bool) 0 !=
 if{
  (L:oh evac signal command,bool) 1 == if{ 1 } els{ 0 }

Should be:

Code:
(A:ELECTRICAL MASTER BATTERY,bool) 0 !=
 if{
  (L:oh evac signal command,bool) 1 == if{ 1 } els{ 0 }
  }
 
But I'm really not sure how to script that.

Came up with this code and it sort of works the way I was planning.
The evac button will not move back out again until the horncutout switch is pressed and then again turn the evac light off again.

But the thing I want is that the evac button will spring back into place without the light go back off.

If I get you right, this should work:

Code:
   <PartInfo>
    <Name>oh_evac_signal_horncut_switch</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:oh evac signal cutout,bool) 50 *
        </Code>
        <Lag>300</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Evac Signal Horn Cutout</TooltipText>
	  <MouseFlags>LeftSingle+LeftRelease+LeftDrag</MouseFlags>
        <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == 
        if{ 1 (>L:oh evac signal cutout,bool) 0 (>L:oh evac signal command,bool) }
        els{ 0 (>L:oh evac signal cutout,bool)  }
      </CallbackCode>
    </MouseRect>
  </PartInfo>
  
  <PartInfo>
    <Name>oh_evac_signal_command</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:oh evac signal command,bool) 50 *
        </Code>
        <Lag>300</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Command Evac Signal</TooltipText>
	  <MouseFlags>LeftSingle</MouseFlags>
        <CallbackCode>
       <CallbackCode>
        1  (>L:oh evac signal command,bool)
        </CallbackCode>
      </CallbackCode>
    </MouseRect>
  </PartInfo>
  
   <PartInfo>
        <Name>oh_evac_visible</Name>
        <Visibility>
            <Parameter>
        	<Code>
        	   (A:ELECTRICAL MASTER BATTERY,bool) 
                   (L:oh evac signal command,bool) and
	        </Code>
            </Parameter>
        </Visibility>
    </PartInfo>


Now, a bit of conceptuals:

Code:
[FONT="Courier New"]! (&gt;L:oh evac signal command,bool)[/FONT]
works in your example because, as the stack is empty at the beginning of the script, it is the same as writing
Code:
[FONT="Courier New"]1 (&gt;L:oh evac signal command,bool)[/FONT].
However, if there is a chance that the stack could not be empty, the value assigned could be uncertain so it is preferable to use the last format. Also &gt; can be replaced with > without trouble, which improves the reading.

When you test for one to several conditions for a true/false value, it is not necessary to conditionaly check for the result of the previous condition as it is already stored in the stack.
For example
Code:
[FONT="Courier New"](A:ELECTRICAL MASTER BATTERY, bool)
 (L:oh evac signal command,bool) and [/FONT]
stores 1 in the stack if it is true, else stores 0

so, if it is true:

1 if{ 1 } els{ 0 } returns 1

and if it is false:

0 if{ 1 } els{ 0 } returns 0

Then the the entire if{} els{} is redundant and can be discarded.

In case you need an inverse result, ie 0 -> 1 and 1 -> 0 , negating the conditional gives the same:

Code:
[FONT="Courier New"](A:ELECTRICAL MASTER BATTERY, bool)
 (L:oh evac signal command,bool) and [B]![/B]
[/FONT]

Also remember that every if{ and els{ must end with a }, to ensure that the script will execute properly. Sometimes, like in your example:

Code:
[FONT="Courier New"]<Code>
      	(A:ELECTRICAL MASTER BATTERY,bool) 0 !=
	if{
		(L:oh evac signal command,bool) 1 == if{ 1 } els{ 0 }
</Code>
[/FONT]
it will work ok because the end of the script finishes the parsing, but if it is otherwise it could turn debuggin into a nightmare.


Tom
 
Last edited:
Once again I'm was not clear about my intention :)

What I was hoping for was:

1. The "oh_evac_signal_command" triggers the evac light.

Button is pressed, light goes on and the button pops back into its original postition and the light still stays on.

2. The "oh_evac_signal_horncut_switch" turn the light back off.


Naruto Kun and Tom, thanks for the clarification.

Tom:
The code you supplied me with does just the same as my old code, but then again I may not been to clear in my intension :)
 
Once again I'm was not clear about my intention :)

What I was hoping for was:

1. The "oh_evac_signal_command" triggers the evac light.

Button is pressed, light goes on and the button pops back into its original postition and the light still stays on.

2. The "oh_evac_signal_horncut_switch" turn the light back off.


Oh Ok, then just change:

in oh_evac_signal_horncut_switch partinfo:

Code:
<CallbackCode>
     (M:Event) 'LeftSingle' scmp 0 == 
        if{ 1 (>L:oh evac signal cutout,bool) 0 (>L:oh evac signal light,bool) }
        els{ 0 (>L:oh evac signal cutout,bool)  }
</CallbackCode>


In oh_evac_signal_command partinfo,

Code:
<MouseFlags>LeftSingle+LeftRelease</MouseFlags>
<CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == 
        if{ 1 (>L:oh evac signal command,bool) 1 (>L:oh evac signal light,bool) }
        els{ 0 (>L:oh evac signal command,bool)  }
</CallbackCode>

and in oh_evac_visible partinfo:

Code:
<Code>
     (A:ELECTRICAL MASTER BATTERY,bool) 
     (L:oh evac signal light,bool) and
</Code>

Tom
 
Okay, now I see what you did.

You made an new L:var called #L:oh evac signal light,bool# and #oh_evac_signal_command# sets the #L:oh evac signal light,bool# to 1 and #oh_evac_signal_horncut_switch# sets the var back to 0.

That will make the light work independently off the original var :)

Did not get it to work the first time, but off course I needed to change the invisible code as well and now it works flawless :)

Thanks for the help :)
 
Last edited:
Back
Top