Difference between revisions of "Controller"
Line 3: | Line 3: | ||
The '''controller''' command returns TRUE if a menu item or key assigned to the controller has been selected or pressed during the current cycle. | The '''controller''' command returns TRUE if a menu item or key assigned to the controller has been selected or pressed during the current cycle. | ||
− | == Syntax == | + | ==<br /> Syntax == |
: controller([[Controller|ctl]] cA) | : controller([[Controller|ctl]] cA) | ||
− | == Remarks == | + | ==<br /> Remarks == |
: Test commands are only valid in an ''if'' statement. | : Test commands are only valid in an ''if'' statement. | ||
Line 17: | Line 17: | ||
: If more than one menu or keyboard entry is assigned to the controller, it does not matter which one is selected/pressed. All of them will cause the '''controller''' command to return TRUE. | : If more than one menu or keyboard entry is assigned to the controller, it does not matter which one is selected/pressed. All of them will cause the '''controller''' command to return TRUE. | ||
− | == Example == | + | ==<br /> Example == |
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
Line 66: | Line 66: | ||
|} | |} | ||
− | == | + | ==<br /> Data types == |
− | + | {{Data Types}} | |
− | ==<br /> | + | ==<br /> See Also == |
− | + | * [[Controller|Controllers]] | |
− | == Sources == | + | ==<br /> Sources == |
* [[WinAGI|WinAGI]] help file | * [[WinAGI|WinAGI]] help file |
Revision as of 15:08, 10 March 2018
This article refers controller-command. For information about Controllers as part of an AGI game, see Controller.
The controller command returns TRUE if a menu item or key assigned to the controller has been selected or pressed during the current cycle.
Syntax
- controller(ctl cA)
Remarks
- Test commands are only valid in an if statement.
- This statement can be combined with the NOT operator (!) to test for a controller NOT being selected.
- The interpreter clears all controllers at the beginning of each cycle.
- If more than one menu or keyboard entry is assigned to the controller, it does not matter which one is selected/pressed. All of them will cause the controller command to return TRUE.
Example
<syntaxhighlight lang="agi"> //build a simple menu structure set.menu("Info"); set.menu.item("About ", c0); set.menu.item("Help ", c1); set.menu("File"); set.menu.item("Save Game <F5>", c2); set.menu.item("Restore Game <F7>", c3); set.menu.item("-------------------", c20); set.menu.item("Restart Game <F9>", c4); set.menu.item("-------------------", c20); set.menu.item("Quit <Alt Z>", c5); //disable the separators disable.item(c20);
//submit menu to agi submit.menu()
//create keyboard shortcuts set.key(0, 63, c2); // 'F5' set.key(0, 65, c3); // 'F7' set.key(0, 67, c4); // 'F9' set.key(26, 0, c5); // 'Alt-Z'
//test for menu or keyboard selections if (controller(c2) {
//save game save.game();
} if (controller(c3) {
//restore game restore.game()
}
</syntaxhighlight>Technical Information
Required interpreter version | Available in all AGI versions |
Bytecode value | 12 (0x0C hex) |
Data types
- Data types
See Also
Sources
- WinAGI help file