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

P3D v1 Altitude Alert

Zeiten

Resource contributor
Messages
444
Country
norway
Hi.

Are stuck with this gauge as I'm not certain about the right syntax.

Making a gauge that turns on a light when the altitude is 1000 ft less/more then what put in the autopilot.

Guess the code must go something like

Code:
0 1000 (A:PLANE ALTITUDE, feet) (A:AUTOPILOT ALTITUDE LOCK VAR, feet) - + rng
if{ 1 (>L:altitude_alert, bool) }
els{ 0 (>L:altitude_alert, bool) }

Any help would be appreciated :)
 
This should work:

Code:
(A:PLANE ALTITUDE, feet) (A:AUTOPILOT ALTITUDE LOCK VAR, feet) - abs 1000 >
if{ 1 (>L:altitude_alert, bool) }
els{ 0 (>L:altitude_alert, bool) }

Tom
 
That worked!
Thanks :)

But here is a follow up.

How on earth to make the light extinguish when you reach the assigned altitude?
 
I don't trully understand your question: the light turns on whenever the altitude difference is +/- 1000 and greater, and extinguishes automatically otherwise. What else do you need?

Tom
 
Sorry about that.

Let say I put the AP to 5000 feet.
The light goes on passing trough 4000 ft.

But I also want the light to go off again when it almost reaches 5000 ft (the assigned altitude).

Example:

5000 is AP altitude.

Light goes ON throughout 4-6000 ft.
Light goes OFF when in range off 4700-5300 ft.
 
Here is my "altitude alert" script:

Code:
    (A:Autopilot altitude lock var, feet) (A:Indicated altitude, feet) - abs d 300 >= r 850 <= and
    (L:B737_AltitudeAlert_Light,bool) ! and
    if{ 1 (>L:B737_AltitudeAlert_Light,bool) }

    (A:Autopilot altitude lock var, feet) (A:Indicated altitude, feet) - abs d 300 < r 850 > or
    (L:B737_AltitudeAlert_Light,bool) and
    if{ 0 (>L:B737_AltitudeAlert_Light,bool) }

I've set my "range" such that the light will come on during either ascent or descent, whenever the a/c is within the target parameter range of 500'... You can adjust the target values however you wish. Note that the script calculates the difference, then duplicates (d) the stack for a subsequent comparison by recalling (r) the calculated difference value.

The second script simply uses the same "500' range" and extinguishes the light when appropriate.

As a matter of practice I deliberately avoid the use of the construct "els{ 0 (>L:B737_AltitudeAlert_Light,bool) }" since it is "uncontrolled" and will simply keep resetting that L:variable 18/second! While "hammering" an L:var won't necessarily cause problems, for me it's a matter of habit to use the same "safe practices" with L:vars as I would with K:Events, since those will cause problems (server flooding among others).
 
Last edited:
As a matter of practice I deliberately avoid the use of the construct "els{ 0 (>L:B737_AltitudeAlert_Light,bool) }" since it is "uncontrolled" and will simply keep resetting that L:variable 18/second! While "hammering" an L:var won't necessarily cause problems, for me it's a matter of habit to use the same "safe practices" with L:vars as I would with K:Events, since those will cause problems (server flooding among others).

Actually in your example your solution is worst than the els{} one, because you are using much more code, which is being interpreted on each cycle. In these cases, the best option should be to save the first evaluation results into registers and then evaluate the inverse:

Code:
 (A:Autopilot altitude lock var, feet) (A:Indicated altitude, feet) - abs d 300 >= r 850 <= and s0 
    (L:B737_AltitudeAlert_Light,bool) s1 ! and 
    if{ 1 (>L:B737_AltitudeAlert_Light,bool) }
    l0 ! l1 and
    if{ 0 (>L:B737_AltitudeAlert_Light,bool) }

Tom
 
Yep Tom, you're right as rain. Why that might save a whole 3.2 milliseconds or thereabouts... :duck:

Seriously, I'll have to keep this in mind for the future. Thanks for the tip... ;)
 
Yep Tom, you're right as rain. Why that might save a whole 3.2 milliseconds or thereabouts... :duck:

Well, bring that to a complex project with a big model and a lot of gauges....:eek:

Seriously myself, one of the weakest point of FS XML scripts is the way they are interpreted. Pushing any variable on the stack is an expensive task, involving a bunch of called functions. Math operations are expensive too. Instead, pushing/popping a register is quite faster and simpler, involving a single assembler-embedded function. I guess this is the reason FS guys implemented registers s0-s49. The effects won't be noticeable in most gauge projects for sure, but may be important in those that push XML code a step forward.

Tom
 
It's really impressive what you guys know!!

Kudos and happy holidays to you all :)
 
Well, bring that to a complex project with a big model and a lot of gauges....:eek:

I'm in the process of wrapping up a HUGE project in which every "gauge" is 3d modeled, and every bit of the XML is embedded in the interior .mdl file, with the exceptions of the FMS and an external module that was programmed to provide some functions that FSX simply doesn't provide.

I've been simply amazed at the performance in the sim.
 
Tom's correct, there's no real "protection" but it most definitely makes changing anything pretty darn difficult! :D
 
Back
Top