Difference between revisions of "AGIWiki/controller"

From ScummVM :: Wiki
Jump to navigation Jump to search
Line 25: Line 25:
  //build a simple menu structure
  //build a simple menu structure
  set.menu("File");
  set.menu("File");
  set.menu.item("Save Game      <F5>", c2);
  set.menu.item("Save Game      <F5>", c2);
  set.menu.item("Restore Game  &lt;F7&gt;", c3);
  set.menu.item("Restore Game  <F7>", c3);


  //submit menu to agi
  //submit menu to agi
Line 46: Line 46:
  ...
  ...
</syntax>
</syntax>
== Technical Information ==
== Technical Information ==



Revision as of 09:40, 25 April 2013


AGIWiki


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

<syntax type="C++">

//build a simple menu structure
set.menu("File");
set.menu.item("Save Game      <F5>", c2);
set.menu.item("Restore Game   <F7>", c3);
//submit menu to agi
submit.menu()
//create keyboard shortcuts
set.key(0, 63, c2); // 'F5'
set.key(0, 65, c3); // 'F7'
//test for menu or keyboard selections
if (controller(c2) {
  //save game
  save.game();
}
if (controller(c3) {
  //restore game
  restore.game()
}
...

</syntax>

Technical Information

Required interpreter version Available in all AGI versions
Bytecode value 12 (0x0C hex)

See Also

Sources