From AGI Wiki
Jump to: navigation, search

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.


controller(ctl cA)


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.


[ build a simple menu system"Info");"About   ", c0);"Help    ", c1);"File");"Save Game      <F5>", c2);"Restore Game   <F7>", c3);"-------------------", c20);"Restart Game   <F9>", c4);"-------------------", c20);"Quit        <Alt Z>", c5);
[ disable the separators
[ submit menu to agi
[ 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
  [ save game;
  [ restore game

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 12 (0x0C hex)

See Also

Player Input Commands