XML: Macros - Universal Timer: Difference between revisions
(Cleanup, comprehensibility, differences between FS9 and FSX, example gauge) |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 55: | Line 55: | ||
=== Gauge Example (FSX) === | === Gauge Example (FSX) === | ||
This is an example gauge for triggering an engine failure after five minutes above a certain temperature treshhold. | This is an example gauge for triggering an engine failure after five minutes above a certain temperature treshhold. In order to capture the absolute start time for the event, a G:var "lock" has to be employed. In this example, the lock will "open" when the engine temperature falls below the temperature treshhold. | ||
<SimBase.Document Type="AceXML" version="1,0"> | <SimBase.Document Type="AceXML" version="1,0"> | ||
| Line 68: | Line 68: | ||
<Script> | <Script> | ||
(A:TURB ENG ITT:1, celsius) 907 > | (A:TURB ENG ITT:1, celsius) 907 > | ||
if{ @SetElapsed(MyTimer,minutes) | (G:Var1) 1 != | ||
and | |||
if{ @SetElapsed(MyTimer,minutes) 1 (>G:Var1) }<br> | |||
@GetElapsed(MyTimer,minutes) 5 > | @GetElapsed(MyTimer,minutes) 5 > | ||
if{ (>K:TOGGLE_ENGINE1_FAILURE) } | if{ (>K:TOGGLE_ENGINE1_FAILURE) }<br> | ||
(A:TURB ENG ITT:1, celsius) 907 < | |||
(G:Var1) 0 != | |||
and | |||
if{ 0 (>G:Var1) } | |||
</Script> | </Script> | ||
</Update><br> | </Update><br> | ||
Latest revision as of 00:04, 26 August 2014
Universal Timer Macros
Making elapsed time based on gauge update cycle is simple to code and easy to understand.
Courtesy of Tom Aguilo (taguilo) in post: http://www.fsdeveloper.com/forum/threads/adding-a-timer.431123/#post-681198
Macros
A group of macros, but with an universal score could be the following. Both macros can be copied and pasted on every gauge so to have elapsed timers available for the entire code.
FS9 syntax:
<Macro Name="GetElapsed"> (P:Absolute time,@2) (L:@1,@2) - abs </Macro> <Macro Name="SetElapsed"> (P:Absolute time,@2) (>L:@1,@2) </Macro>
FSX syntax:
<Macro Name="GetElapsed"> <MacroValue>(P:Absolute time,@2) (L:@1,@2) - abs</MacroValue> </Macro> <Macro Name="SetElapsed"> <MacroValue>(P:Absolute time,@2) (>L:@1,@2)</MacroValue> </Macro>
Implementation
The above macros are called within update sections in the following way:
@SetElapsed(name_of_var,unit) @GetElapsed(name_of_var,unit)
Gauge Example (FSX)
This is an example gauge for triggering an engine failure after five minutes above a certain temperature treshhold. In order to capture the absolute start time for the event, a G:var "lock" has to be employed. In this example, the lock will "open" when the engine temperature falls below the temperature treshhold.
<SimBase.Document Type="AceXML" version="1,0"> <SimGauge.Gauge id="Gauge" ArtDirectory=".">
<Macro Name="GetElapsed"> <MacroValue>(P:Absolute time,@2) (L:@1,@2) - abs</MacroValue> </Macro>
<Macro Name="SetElapsed"> <MacroValue>(P:Absolute time,@2) (>L:@1,@2)</MacroValue> </Macro>
<Update> <Script> (A:TURB ENG ITT:1, celsius) 907 > (G:Var1) 1 != and if{ @SetElapsed(MyTimer,minutes) 1 (>G:Var1) }
@GetElapsed(MyTimer,minutes) 5 > if{ (>K:TOGGLE_ENGINE1_FAILURE) }
(A:TURB ENG ITT:1, celsius) 907 < (G:Var1) 0 != and if{ 0 (>G:Var1) } </Script> </Update>
</SimGauge.Gauge> </SimBase.Document>