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 ''' ...")
 
(Cleanup, comprehensibility, differences between FS9 and FSX, example gauge)
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.
 
<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)  }
     if{  @SetElapsed(MyTimer,minutes)  }<br>
    ...
    ...
     @GetElapsed(MyTimer,minutes) 5 >
     @GetElapsed(MyTimer,minutes) 5 >
     if{ do something }
     if{ (>K:TOGGLE_ENGINE1_FAILURE) }
    ...
</Script>
  </Update>
  </Update><br>
 
</SimGauge.Gauge>
Both macros can be copied and pasted on every gauge so to have elapsed timers available for the entire code.
</SimBase.Document>


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

Revision as of 23:00, 25 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.

<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 > if{ @SetElapsed(MyTimer,minutes) }
@GetElapsed(MyTimer,minutes) 5 > if{ (>K:TOGGLE_ENGINE1_FAILURE) } </Script> </Update>
</SimGauge.Gauge> </SimBase.Document>