Example #2 - Map Mode Control
As was mentioned in the section on setting the Mode, it is possible to use the CMS to control which Mode the map is using via the CURRENTMODE variable. In this example, we'll implement a cycling mode switch that operates much like the hardware mode switches on the FighterStick and ProThrottle.
The only real fact of interest here is that, to cycle through the three Modes, we need to set the CURRENTMODE variable to 0, then 1, then 2, then back to 0. In this example, we use one of the internal Analog Variables, A1, to keep track of which mode we're going to set. That variable will be incremented by one every time a button is pressed, and when it goes above 2, we'll reset it to zero. A sequence is probably the simplest way to implement this since we can use the WAIT() function to stall the sequence until our button is clicked.
The Script
For this map, we'll assume that there's just a CombatStick in the map and we want the Mode button to be Button 2 on that device. The script would look something like this:
SCRIPT
SEQUENCE
WAIT( JS1.B2 ); // Wait here until JS1.B2 clicks
A1 = A1 + 1; // Add 1 to our Mode counter
IF( [ A1 > 3 ] ) THEN // If the value is over 3 then
A1 = 0; // set it back to 0
ENDIF
CURRENTMODE = A1; // Now copy it to CURRENTMODE
ENDSEQUENCE
ENDSCRIPT
JS1.B2 will increment A1 by 1 every time it's clicked. When A1 goes above three, it gets reset to zero. The values will cycle 0, 1, 2, 3, 0, 1, 2, 3, etc. thus cycling through the four modes, just as we intended. Since this doesn't control any CM Device axes or buttons, there is really nothing that needs to be assigned in the GUI except that Button 2 on the CombatStick should be assigned to "None" so it doesn't interfere with whatever else the map is doing.
Another method would be to control the four modes with a single 4-way hat. This has the advantage that all four modes are available instantly without having to cycle through the other 3 modes, and we can tell which Mode we are in by the direction that we push the hat.
For this example we'll assume we have a FighterStick and wish to use Hat 3 to control the four Modes. Hat 3 generates Buttons 13 through 16. The script itself is straightforward, just a series of nested IF/THEN/ELSE blocks that set the CURRENTMODE variable based on which of the current position of Hat 3. It's useful to remember when using hats that they can only have one position active at a time so we don't need to make any allowance for a situation where B13 and B14 were closed at the same time.
The script might look like this:
SCRIPT
IF( JS1.B13 ) THEN
CURRENTMODE = MODE1;
ELSE
IF( JS1.B14 ) THEN
CURRENTMODE = MODE2;
ELSE
IF( JS1.B15 ) THEN
CURRENTMODE = MODE3;
ELSE
IF( JS1.B16 ) THEN
CURRENTMODE = MODE4;
ENDIF
ENDIF
ENDIF
ENDIF
ENDSCRIPT
Out in the GUI, the Hat 3 positions should, of course, be programmed to "NONE" so as not to send any commands directly.