XML: Increment Variable w/Modulo Reset: Difference between revisions

From FSDeveloper Wiki
Jump to navigationJump to search
(New page: ==XML: Increment Variable w/Modulo Reset== {{Infobox-Applicable-FSVersion | FSXA = true | FSX = true | FS2004 = true | FS2002 = false | XP10 = false | XP9 = false }} The following scri...)
 
No edit summary
Line 11: Line 11:


The following script shows how to increment the custom (L:Variable,unit) value by 1 on each "click". The number preceeding the modulo operator (%) is the upper limit, at which point the variable will reset back to zero!
The following script shows how to increment the custom (L:Variable,unit) value by 1 on each "click". The number preceeding the modulo operator (%) is the upper limit, at which point the variable will reset back to zero!
'''NOTE: this technique works for integers only. Fractional increment/decrement should use other methods.'''


  0 + click = 1; 1 mod 5 = 1
  0 + click = 1; 1 mod 5 = 1

Revision as of 09:57, 29 June 2012

XML: Increment Variable w/Modulo Reset

The following script shows how to increment the custom (L:Variable,unit) value by 1 on each "click". The number preceeding the modulo operator (%) is the upper limit, at which point the variable will reset back to zero!

NOTE: this technique works for integers only. Fractional increment/decrement should use other methods.

0 + click = 1; 1 mod 5 = 1
1 + click = 2; 2 mod 5 = 2
2 + click = 3; 3 mod 5 = 3
3 + click = 4; 4 mod 5 = 4
4 + click = 5; 5 mod 5 = 0
   <MouseRect>
     <Cursor>Hand</Cursor>
     <TooltipText>Window Left</TooltipText>
     <CallbackCode>
       (L:SwitchWindowLeft, enum) ++ 5 % (>L:SwitchWindowLeft, enum)
     </CallbackCode>
   </MouseRect>