XML: Macros - Universal Timer: Difference between revisions

From FSDeveloper Wiki
Jump to navigationJump to search
(Created page with "{{Infobox-Applicable-FSVersion | P3D = true | FSXA = true | FSX = true | FS2004 = true | FS2002 = false | FS2000 = unknown | FS98 = unknown }} ''' Universal Timer Macros ''' ...")
 
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
| FS98 = unknown
| FS98 = unknown
}}
}}
''' Universal Timer Macros '''
 
 
 
== Universal Timer Macros ==


Making elapsed time based on gauge update cycle is simple to code and easy to understand.
Making elapsed time based on gauge update cycle is simple to code and easy to understand.
Line 14: Line 17:
Courtesy of Tom Aguilo (taguilo) in post: http://www.fsdeveloper.com/forum/threads/adding-a-timer.431123/#post-681198
Courtesy of Tom Aguilo (taguilo) in post: http://www.fsdeveloper.com/forum/threads/adding-a-timer.431123/#post-681198


A group of macros, but with an universal score could be :
 
 
=== 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">
  <Macro Name="GetElapsed">
Line 23: Line 34:
  </Macro>
  </Macro>


And then using:
'''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)
  @SetElapsed(name_of_var,unit)
  @GetElapsed(name_of_var,unit)
  @GetElapsed(name_of_var,unit)


For example (pseudocode):
 
=== 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="."><br>
<Macro Name="GetElapsed">
<MacroValue>(P:Absolute time,@2) (L:@1,@2) - abs</MacroValue>
</Macro><br>
<Macro Name="SetElapsed">
<MacroValue>(P:Absolute time,@2) (>L:@1,@2)</MacroValue>
</Macro><br>
  <Update>
  <Update>
<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{ do something }
     if{ (>K:TOGGLE_ENGINE1_FAILURE) }<br>
     ...
     (A:TURB ENG ITT:1, celsius) 907 <
  </Update>
    (G:Var1) 0 !=
 
    and
Both macros can be copied and pasted on every gauge so to have elapsed timers available for the entire code.
    if{ 0 (>G:Var1) }
</Script>
  </Update><br>
</SimGauge.Gauge>
</SimBase.Document>


[[category:Aircraft Design]]
[[category:Aircraft Design]]
[[category:Panel and Gauge Design]]
[[category:Panel and Gauge Design]]

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>