• 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 A simple, pause-sensitive "timer"

Heretic

Resource contributor
Messages
6,830
Country
germany
Don't want to clutter up the timer thread, so here's another one.

The easiest form to implement a timer, or something counting up or down, is something akin to this:

Code:
<Update>
<Script>
(L:Variable,enum) 0.055556
(P:Simulation Rate,number) *
+ (>L:Variable,enum)
</Script>
</Update>

This looks clean and simple and the 0.055556 ensures that the variable is roughly incremented by 1 unit per second as the default update rate for gauges is 18 Hz or 18 times per second.

There is, however, a problem, namely that FSX will continue to run this script despite the sim being paused. The result can be undesired side effects, but there's a solution in form of a key event capture, an L: variable and a comparison.

Code:
<Update>
<Script>
(P:ABSOLUTE TIME,seconds) (L:PAUSE,enum) !=
(A:IS SLEW ACTIVE,bool) !
and
if{ (L:Variable,enum) 0.055556
(P:Simulation Rate,number) *
+ (>L:Variable,enum) }
</Script>
</Update>

  <KeyMap>
  <Trigger>
  <KeyEvent>PAUSE_TOGGLE</KeyEvent>
  <Script>
  (P:ABSOLUTE TIME,seconds) (>L:PAUSE,enum)
  </Script>
  </Trigger>
  </KeyMap>

Whenever the sim is paused with the "pause" function, the gauge will assign the current time to an L: var. This L: var is compared against the current simulation time. If they match, the timer will not be run and vice versa.

Might be old news to some, but those who didn't know this yet, now have yet another lean and clean possibility to implement a timer.


- Edit: Added simulation rate.
 
Last edited:
Nice, very simple, and in FSX syntax, too. I like the use of PAUSE_TOGGLE to remember absolute time. Can you add simulation rate to it!

I'm volunteering to edit and consolidate the timer wikis and I'll add your FSX syntax script.

Bob
 
Again, please be aware that Event Captures don't work in other views different than the one in where they are coded.
Then, if PAUSE is pressed in External view and <KeyEvent>PAUSE_TOGGLE</KeyEvent> is in a VC gauge, it won't work. Check Bob's link to a post showing proper code to detect pause in every situation.

Anyway XMLEVENT class in XMTools was mostly developed to solve this issue.

Tom
 
Last edited:
Here's a "one view fits all" configuration. Requires Tom Aguilo's "XML Tools.dll".

Code:
<Update>
<Script>
(P:ABSOLUTE TIME,seconds) (L:PAUSE,enum) !=
(A:IS SLEW ACTIVE,bool) !
and
if{ (L:Variable,enum) 0.055556
(P:Simulation Rate,number) *
+ (>L:Variable,enum) }
</Script>
</Update>

<Update>
<Script>
'PAUSE_TOGGLE' (>C:XMLEVENTS:EventName,string)
'(P:ABSOLUTE TIME,seconds) (>L:PAUSE,enum)' (>C:XMLEVENTS:EventString,string)
</Script>
</Update>
 
Last edited:
Again, please be aware that Event Captures don't work in other views different than the one in where they are coded.
Then, if PAUSE is pressed in External view and <KeyEvent>PAUSE_TOGGLE</KeyEvent> is in a VC gauge, it won't work.
OK, I see. The sim will pause, but a PAUSE_TOGGLE trap in a non-visible panel gauge wont catch it and process its trap script. Which brings me to the obvious question, is there a logical reason there is no A:Var for Pause state?

Bob
 
It's the least I can do. Because I am impatient. I do wikis and guidebooks on things I'm currently interested in because I get frustrated searching through years of posts in various forums for something that I vaguely remember. I make time to help with the institutional memory -- I don't have the answers; I can only help write them down I guess.
 
It's the least I can do. Because I am impatient. I do wikis and guidebooks on things I'm currently interested in because I get frustrated searching through years of posts in various forums for something that I vaguely remember. I make time to help with the institutional memory -- I don't have the answers; I can only help write them down I guess.

Well, that's why I like to create threads with problems I solve myself after an hour of trial & error. They're here, they have a solution and everyone can read them. :)

P.S:
You might want to include the XMLTools based timer as well.
 
The next variation for those who are using Doug Dawson's XML sound gauge in their panel anyway. "dsd_fsx_xml_sound.gau" comes with a handy L: variable that indicates the sim's pause state and works reliably from all views.

Code:
<Update>
<Script>
(L:FSSimIsPaused,number) 1 !=
(A:IS SLEW ACTIVE,bool) 1 !=
and
if{ (L:Variable,enum) 0.055556 (P:Simulation Rate,number) * + (>L:Variable,enum) }
</Script>
</Update>
 
Last edited:
Hi,
Maybe I'm completely missing the point of this thread, but what is easier then:
Code:
(* Start timer *)
(L:TimerRunning,bool) !
if{
   (P:ABSOLUTE TIME,seconds) (>L:StartTime,seconds)
   1 (>L:TimerRunning,bool)
}
 
(* Elapsed time *)
(L:TimerRunning,bool)
if{ (P:ABSOLUTE TIME,seconds) (L:StartTime,seconds) - (>L:ElapsedTime,seconds) }
 
(* Stop timer *)
0 (>L:TimerRunning,bool)

In general, I think that making timers based on incrementing counters by gauge-scheduling is a not a good idea.
Because:
- Counting-based timers are depending on schedule frequency; even worse: scheduling might not be accurate (see Note-1 below)
- Counting-based timers are dependant on PAUSE.
- Counting-based timers are depending on SimRate; besides, the SimRate variable is flawed (see note-2 below)
True; all these factors can be countered with additional code. As explained in previous posts.
But I wouldn't call this "easy" ;)
Comparing against (P:ABSOLUTE TIME,seconds) doesn't have all these problem, since it automatically stops in PAUSE and adapts to the SimRate.

Note-1:
Due to "stutters", or when framerate (temporary or not) becomes less then 15-16 fps, sometimes a gauge schedule is skipped.
Which makes the timer inaccurate.
Just try this:
Make a gauge that both makes a timer based on counting each schedule, and a timer based on comparing against AbsoluteTime.
Now, make FS run at 10 fps or so (just open a lot of views) and observe the missed schedules.

Note-2:
Var (P:Simulation Rate,number) is flawed: For SimRates 8 and higher, it always returns "4"

Although I must admit: changing the time in FSX flaws a running timer :D

Cheers, Rob

PS: You might also want to take SLEW into account.
Depending if you want a timer to keep running when Slew is Active, or not (using var (A:IS SLEW ACTIVE,bool) ).
Note that, unlike in PAUSE, system time normally runs during SLEW.
 
Last edited:
Nice response. Thanks very much. It is easy to see advantages to absolute time based timers.

Looking into your, and Tom's, responses further, I discovered that your Note-2 about (P:Simulation Rate,number) applies to FSX (and presumably P3D), but, interestingly, not FS9. Also, I just learned that in FSX that the ABSOLUTE TIME clock speeds up only through sim rate 4x; at higher sim rates, ABSOLUTE TIME still seems to run at 4x. From that point of view, would (P:SIMULATION RATE, number) be considered "accurate" at the high sim rates?

Anyway, I see your point about cycle count vs. absolute time timers. I need to think about high (8x +) sim rates ... do timers work? and should I care if they didn't at those high rates?

Thanks again!

Bob
 
Last edited:
Is there a reason everybody uses ABSOLUTE TIME (based on current sim time as offset by 12:00am Jan 1, 0000) versus ELAPSED SECONDS which is the number of seconds the sim has been running? Or is ELAPSED SECONDS not available in XML?
 
That's not available in XML, Ed...

...or at least it's not documented as available in any of the many SDKs to which I have reference. :confused:
 
Hi,
Maybe I'm completely missing the point of this thread...

Actually I think you missed this thread:

http://www.fsdeveloper.com/forum/threads/adding-a-timer.431123/

In where issues related to cycle counters had been already discussed.

Now, Simrate above 4x is indeed flawed and it's another negative factor, although in aircraft with complex panels it is not recommendable at all to go faster than 4x because most critical systems -like the autopilot- won't work properly.

And SLEW is a factor too, but only for timers related to speed. Engine parameters are all freezed in SLEW mode so there should be no different behavior.

Although I must admit: changing the time in FSX flaws a running timer :D

Yes of course, there is always chances that the user could make an action that flaws the precision of the data returned.

Tom
 
Hi,
Maybe I'm completely missing the point of this thread, but what is easier then:
Code:
...

Hm...

Code:
<Update>
<Script>
(L:CONDITION VARIABLE, bool)
if{
(L:TimerRunning,bool) !
if{ (P:ABSOLUTE TIME,seconds) (>L:StartTime,seconds) 1 (>L:TimerRunning,bool) }

(L:TimerRunning,bool)
if{ (P:ABSOLUTE TIME,seconds) (L:StartTime,seconds) - (>L:ElapsedTime,seconds)
    (L:Variable,enum) (L:ElapsedTime,seconds) + (>L:Variable,enum) }

(L:Variable,enum) 100 &gt;
if{ 1 (&gt;L:BLOW SOMETHING UP, bool) 0 (>L:TimerRunning,bool) }
}
</Script>
</Update>

In general, I think that making timers based on incrementing counters by gauge-scheduling is a not a good idea.
Because:
- Counting-based timers are depending on schedule frequency; even worse: scheduling might not be accurate (see Note-1 below)
- Counting-based timers are dependant on PAUSE.
- Counting-based timers are depending on SimRate; besides, the SimRate variable is flawed (see note-2 below)
True; all these factors can be countered with additional code. As explained in previous posts.
But I wouldn't call this "easy" ;)
Comparing against (P:ABSOLUTE TIME,seconds) doesn't have all these problem, since it automatically stops in PAUSE and adapts to the SimRate.

The code, albeit more robust (save for the "change sim time" caveat, as you've pointed out) doesn't really qualify as "simple" in my book.

For several timers at once, you could use Tom's macro-based approach, but it still involves more lines of code than the absolute minimal version of an update cycle timer (with the XML Sound gauge).

Note-1:
Due to "stutters", or when framerate (temporary or not) becomes less then 15-16 fps, sometimes a gauge schedule is skipped.
Which makes the timer inaccurate.
Just try this:
Make a gauge that both makes a timer based on counting each schedule, and a timer based on comparing against AbsoluteTime.
Now, make FS run at 10 fps or so (just open a lot of views) and observe the missed schedules.

What would happen if you set the update frequency to a value lower than 18 Hz (if that's even possible), say 9 Hz or so and adjust the increment accordingly?

Note-2:
Var (P:Simulation Rate,number) is flawed: For SimRates 8 and higher, it always returns "4"

I know that more impatient souls merrily use simrates higher than 4 on their transatlantic for transcontinental flights, but considering that time acceleration larger than 4 also "breaks" AI traffic and any real wether updates, I think it's fair game for a puny timer.

PS: You might also want to take SLEW into account.
Depending if you want a timer to keep running when Slew is Active, or not (using var (A:IS SLEW ACTIVE,bool) ).
Note that, unlike in PAUSE, system time normally runs during SLEW.

Done. Thanks for pointing that out.
 
Hi All,

A few reactions, and a additional discovery I just found ...

Tom:
Actually I think you missed this thread:
Yes, I did miss that. Sorry, going to read that later ;)

"Heretic":
What would happen if you set the update frequency to a value lower than 18 Hz (if that's even possible), say 9 Hz or so and adjust the increment accordingly?
Yes, that will work because the chance of lost schedule is almost none (because no-one probably flies with 10 fps or lower).
Just another note on "lost schedules" you should be aware of:
You would expect that if you issue an event in an XML gauge, that the result of the event is visible in the corresponding A:Var at the next schedule of your gauge.
Normally this is the case.
However, with framerate less then 15/16 (and an update freq. 18 Hz), this is not always true. It might take 2 or even 3 schedules before it's visible ....
Just be aware of that.
Example: if you issue some Toggle event, and test the related A:var in the next schedule, the effect might not be reflected yet. So you issue another Toggle event, which undoes the first one. And so on ....
It will solve itself, but it may take several "Toggles" before you are in the right state.
That's why it's always better, to use the _ON and _OFF variants of an event (if available) instead of the Toggle variant of a function.
(or: if it's a critical function, use it in a gauge with eg. UpdateFreq=6; i.e. 6 Hz)

Bob:
Also, I just learned that in FSX that the ABSOLUTE TIME clock speeds up only through sim rate 4x; at higher sim rates, ABSOLUTE TIME still seems to run at 4x.
Well you're in for a surprise I just discovered when testing this stuff again.
Both SimRate var and AbsoluteTime are limited (in FSX) to 4* acceleration.
HOWEVER: THIS IS ONLY ON THE GROUND !!!
If the aircraft is in the air, it works just like you would expect !! So NO 4* acceleration limit for both the SimRate var and AbsoluteTime..
Go figure .....:confused:


Another remark about using SimRate higher then 4.
I agree, not very relevant in normal flying and may give problems for functions like the standard AP and scheduled AI.
However, I do have an application for higher SimRates then 4.
You may have heard of my "spaceflight" addon; I know, a very peculiar use of FSX ...;)
But to simulate real speeds in space (like 20.000 Knots), where the abs. max speed in FSX is 2665 Knots, I use SimRate 8 or 16 sometimes.
Which works fine, if also your instruments readouts, controller sensitivies and timers are automatically adapted to the SimRate. Which I've done.
Doesn't work with AI spacecraft launched by the normal AI schedules, but works fine with AI spacecraft started with the AICarriers2 addon.
(I use AICarriers2 to start AI "carriers" at e.g 900.000 ft)

Cheers, Rob
 
Last edited:
Well you're in for a surprise I just discovered when testing this stuff again.
Both SimRate var and AbsoluteTime are limited (in FSX) to 4* acceleration.
HOWEVER: THIS IS ONLY ON THE GROUND !!!
If the aircraft is in the air, it works just like you would expect !! So NO 4* acceleration limit for both the SimRate var and AbsoluteTime..
Go figure .....:confused:
hahahaha, what a little minefield this is
 
Yes, that will work because the chance of lost schedule is almost none (because no-one probably flies with 10 fps or lower).

Is the absolute lowest limit in FS 1 Hz?

Just another note on "lost schedules" you should be aware of:
You would expect that if you issue an event in an XML gauge, that the result of the event is visible in the corresponding A:Var at the next schedule of your gauge.
Normally this is the case.
However, with framerate less then 15/16 (and an update freq. 18 Hz), this is not always true. It might take 2 or even 3 schedules before it's visible ....
Just be aware of that.

I'm only using timers for airframe icing, so it doesn't matter if the wing ices after 15.0 or 15.3 minutes. ;)

Example: if you issue some Toggle event, and test the related A:var in the next schedule, the effect might not be reflected yet. So you issue another Toggle event, which undoes the first one. And so on ....
It will solve itself, but it may take several "Toggles" before you are in the right state.
That's why it's always better, to use the _ON and _OFF variants of an event (if available) instead of the Toggle variant of a function.
(or: if it's a critical function, use it in a gauge with eg. UpdateFreq=6; i.e. 6 Hz)

Or...
Code:
(L:TIMED CONDITION,bool) 100 &gt;
(L:TOGGLE VAR,bool) !
and
if{ 1 (>L:TOGGLE VAR,bool) }


Well you're in for a surprise I just discovered when testing this stuff again.
Both SimRate var and AbsoluteTime are limited (in FSX) to 4* acceleration.
HOWEVER: THIS IS ONLY ON THE GROUND !!!
If the aircraft is in the air, it works just like you would expect !! So NO 4* acceleration limit for both the SimRate var and AbsoluteTime..
Go figure .....:confused:

Heh!


You may have heard of my "spaceflight" addon; I know, a very peculiar use of FSX ...;)

The "very" should be bigger. :D
 
Back
Top