Difference between revisions of "Controller"

From AGI Wiki
Jump to navigationJump to search
(Created page with "__NOTOC__ {{AGIWiki}} ''This article refers controller-command. For information about Controllers as part of an AGI game, see Controller.'' The '''controller...")
 
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
+
''This article refers the controller command. For information about Controllers as part of an AGI game, see [[Controllers]].''
  
{{AGIWiki}}
+
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]].
  
''This article refers controller-command. For information about Controllers as part of an AGI game, see [[Controller|Controller]].''
+
== Syntax ==
  
The '''controller''' command returns TRUE if a menu item or key assigned to the controller has been selected or pressed during the current cycle.
+
controller([[controllers|ctl]] cA)
  
== Syntax ==
+
== Remarks ==
  
: controller([[Controller|ctl]] cA)
+
Test commands are only valid in an <code>if</code> statement.
  
== Remarks ==
+
This test command can be combined with the <code>NOT</code> operator to test for a controller NOT being selected.
  
: Test commands are only valid in an ''if'' statement.
+
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.
  
: This statement can be combined with the NOT operator (!) to test for a controller NOT being selected.
+
AGI clears all controllers at the beginning of each [[interpreter cycle]].
  
: The interpreter clears all controllers at the beginning of each cycle.
+
== Possible Errors ==
  
: 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.
+
AGI does not validate the argument '''cA''' to be sure it points to a valid controller. If '''cA''' is invalid, when AGI accesses the [[controllers#evaltable|controller evaluation table]], it will overflow and read invalid memory, leading to unpredictable results.
  
 
== Example ==
 
== Example ==
<syntax type="C++">
+
 
//build a simple menu structure
+
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="agi">
 +
[ build a simple menu system
 
set.menu("Info");
 
set.menu("Info");
 
set.menu.item("About  ", c0);
 
set.menu.item("About  ", c0);
Line 34: Line 36:
 
set.menu.item("-------------------", c20);
 
set.menu.item("-------------------", c20);
 
set.menu.item("Quit        <Alt Z>", c5);
 
set.menu.item("Quit        <Alt Z>", c5);
//disable the separators
+
[ disable the separators
 
disable.item(c20);
 
disable.item(c20);
  
//submit menu to agi
+
[ submit menu to agi
 
submit.menu()
 
submit.menu()
  
//create keyboard shortcuts
+
[ create keyboard shortcuts
set.key(0, 63, c2); // 'F5'
+
set.key(0, 63, c2); 'F5'
set.key(0, 65, c3); // 'F7'
+
set.key(0, 65, c3); 'F7'
set.key(0, 67, c4); // 'F9'
+
set.key(0, 67, c4); 'F9'
set.key(26, 0, c5); // 'Alt-Z'
+
set.key(26, 0, c5); 'Alt-Z'
  
//test for menu or keyboard selections
+
[ test for menu or keyboard selections
if (controller(c2) {
+
if(controller(c2)
   //save game
+
  {
 +
   [ save game
 
   save.game();
 
   save.game();
}
+
  }
if (controller(c3) {
+
if(controller(c3)
   //restore game
+
  {
 +
   [ restore game
 
   restore.game()
 
   restore.game()
}
+
  }
</syntax>
+
</syntaxhighlight>
  
 
== Technical Information ==
 
== Technical Information ==
  
 
{| border="1" cellpadding="2"
 
{| border="1" cellpadding="2"
| style="background-color: #efefef" | '''Required interpreter version'''
+
| style="background-color: #efefef" width="200" | '''Required Interpreter Version:'''
| Available in all AGI versions
+
| width="175" | Available in all AGI versions.
 
|-
 
|-
| style="background-color: #efefef" | '''Bytecode value'''
+
| style="background-color: #efefef" | '''Byte-Code Value:'''
 
| 12 (0x0C hex)
 
| 12 (0x0C hex)
 
|}
 
|}
Line 69: Line 73:
 
== See Also ==
 
== See Also ==
  
* [[Controller|Controllers]]
+
[[Player Input Commands]]<br />
 
+
[[Controllers]]<br />
== Sources ==
+
[[Category:Commands]]<br />
 
 
* [[WinAGI|WinAGI]] help file
 
 
 
[[Category:Logic Commands]]
 
[[Category:Test Commands]]
 

Latest revision as of 14:52, 21 April 2019

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

Code:

<syntaxhighlight lang="agi"> [ 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()
 }

</syntaxhighlight>

Technical Information

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

See Also

Player Input Commands
Controllers