Controller: Difference between revisions
sierraw>Andrew Branscom m 10 revisions imported |
|||
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:AGI Pages]] | |||
[[Category:AGI Pages to be Edited]] | |||
[[AGI Logic Commands by Name|Return to Logic Commands by Name]] | |||
<div align="center"><span style="font-size: 22pt">controller</div> | |||
<br /> | |||
==<br /> Introduction == | |||
''This article refers the controller command. For information about Controllers as part of an AGI game, see [[Controllers]].'' | ''This article refers the controller command. For information about Controllers as part of an AGI game, see [[Controllers]].'' | ||
The '''controller''' test command returns TRUE if a [[menu]] item or [[key]] assigned to the [[controller]] has been selected or pressed during the current [[interpreter cycle]]. | The '''controller''' test command returns TRUE if a [[menu]] item or [[key]] assigned to the [[controller]] has been selected or pressed during the current [[AGI Interpreter Cycle|interpreter cycle]]. | ||
== Syntax == | == Syntax == | ||
| Line 15: | Line 24: | ||
AGI checks the [[controllers#evaltable|controller evaluation table]] entry for '''cA''' and returns TRUE if the controller has been activated. If more than one menu or keyboard entry is assigned to the controller, it does not matter which one is selected/pressed. Any of them will cause the '''controller''' command to return TRUE. | AGI checks the [[controllers#evaltable|controller evaluation table]] entry for '''cA''' and returns TRUE if the controller has been activated. If more than one menu or keyboard entry is assigned to the controller, it does not matter which one is selected/pressed. Any of them will cause the '''controller''' command to return TRUE. | ||
AGI clears all controllers at the beginning of each [[interpreter cycle]]. | AGI clears all controllers at the beginning of each [[AGI Interpreter Cycle|interpreter cycle]]. | ||
== Possible Errors == | == Possible Errors == | ||
| Line 71: | Line 80: | ||
|} | |} | ||
== | ==<br /> References == | ||
<references /> | |||
==<br /> Related Links == | |||
[[Player Input Commands]] | * [[Player Input Commands]] | ||
[[Controllers]]<br /> | * [[Controllers]] | ||
[[Category:Commands]] | <br /> | ||
[[AGI Logic Commands by Name#Commands|< AGI Logic Command Index]] | |||
| |||
[[Category:Commands]] | |||
[[Category:AGI Logic Commands]] | |||
Latest revision as of 17:48, 4 April 2025
Return to Logic Commands by Name
Introduction
This article refers the controller command. For information about Controllers as part of an AGI game, see Controllers.
The controller test command returns TRUE if a menu item or key assigned to the controller has been selected or pressed during the current interpreter cycle.
Syntax
controller(ctl cA)
Remarks
Test commands are only valid in an if statement.
This test command can be combined with the NOT operator to test for a controller NOT being selected.
AGI checks the controller evaluation table entry for cA and returns TRUE if the controller has been activated. If more than one menu or keyboard entry is assigned to the controller, it does not matter which one is selected/pressed. Any of them will cause the controller command to return TRUE.
AGI clears all controllers at the beginning of each interpreter cycle.
Possible Errors
AGI does not validate the argument cA to be sure it points to a valid controller. If cA is invalid, when AGI accesses the controller evaluation table, it will overflow and read invalid memory, leading to unpredictable results.
Example
[ build a simple menu system
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()
}Technical Information
| Required Interpreter Version: | Available in all AGI versions. |
| Byte-Code Value: | 12 (0x0C hex) |
References