Difference between revisions of "STICK"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
m (Text replacement - "Qbasic" to "QBasic")
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''STICK''' function returns the directional coordinate move of game port (&H201) joystick or USB controller devices.
+
The '''STICK''' function returns the directional axis coordinate move of game port (&H201) joystick or USB controller devices.
  
  
Line 6: Line 6:
  
  
QB64 {{PageSyntax}}
+
== QB64 Syntax ==
:: coordinate_move% = STICK(direction%[, 2])  
+
:: coordinate_move% = STICK(''direction%''[, ''axis_number%''])  
  
  
 
''Description:''
 
''Description:''
* Qbasic direction values are only 0 to 3 for 2 joysticks maximum.
+
* '''QB64''' allows any number of coordinate pairs for more than two game device controllers. STICK will not read a mouse axis.
* '''QB64''' allows any number of coordinate pairs for more than two game device controllers.
+
* ''axis_number'' can be used as the next axis parameter for controllers with multiple axis using the SAME ''directional'' parameters.
* ''2'' can be used as the second parameter for controllers with dual controlled sticks using the SAME ''directional'' parameters.
+
* The ''axis_number'' 1 can be omitted for the main stick column and row parameter reads.
* Returns coordinate values from 1 to 254. Qbasic only returned values from 1 to 200.
+
* Point of view "hats" also have 2 axis. Slide, turn or twist controls have one. The device determines the order of the axis.
 +
* Returns coordinate values from 1 to 254. QBasic only returned values from 1 to 200.
 
* STICK(0) is required to get values from the other STICK functions. Always read it first!
 
* STICK(0) is required to get values from the other STICK functions. Always read it first!
 
{{WhiteStart}}'''STICK(0) returns the column coordinate of device 1. Enables reads of the other STICK values.'''
 
{{WhiteStart}}'''STICK(0) returns the column coordinate of device 1. Enables reads of the other STICK values.'''
 
'''STICK(1) returns row coordinate of device 1.'''
 
'''STICK(1) returns row coordinate of device 1.'''
 
STICK(2) returns column coordinate of device 2. (second joystick if used)
 
STICK(2) returns column coordinate of device 2. (second joystick if used)
STICK(3) returns row coordinate of device 2 if used.
+
STICK(3) returns row coordinate of device 2 if used. (QBasic maximum was 2 controllers)
 
'''STICK(4) returns column coordinate of device 3. (other joysticks if used in QB64 only!)'''
 
'''STICK(4) returns column coordinate of device 3. (other joysticks if used in QB64 only!)'''
 
'''STICK(5) returns row coordinate of device 3 if used.'''
 
'''STICK(5) returns row coordinate of device 3 if used.'''
Line 25: Line 26:
 
* '''QB64''' allows more joysticks by extending the numbers in pairs like device 3 above. EX: STICK(6): STICK(7) 'device 4
 
* '''QB64''' allows more joysticks by extending the numbers in pairs like device 3 above. EX: STICK(6): STICK(7) 'device 4
 
* '''QB64''' allows a dual stick to be read using the same first parameters and 2 as the second parameter. EX: STICK(0, 2)
 
* '''QB64''' allows a dual stick to be read using the same first parameters and 2 as the second parameter. EX: STICK(0, 2)
 +
* '''There will not be an error if you try to read too many device axis or buttons!'''
  
  
Line 59: Line 61:
 
DO: {{Cl|_LIMIT}} 50
 
DO: {{Cl|_LIMIT}} 50
 
   {{Cl|LOCATE}} 10, 1
 
   {{Cl|LOCATE}} 10, 1
   {{Cl|PRINT}} "  X    Main    Y          Slider        Z-axis         POV"
+
   {{Cl|PRINT}} "  X    Main    Y          Slider        Z-axis           POV"
   {{Cl|PRINT}} {{Cl|STICK}}(0), {{Cl|STICK}}(1), {{Cl|STICK}}(0, 2), {{Cl|STICK}}(1, 2), {{Cl|STICK}}(0, 3); "  "
+
   {{Cl|PRINT}} {{Cl|STICK}}(0, 1), {{Cl|STICK}}(1, 1), {{Cl|STICK}}(0, 2), {{Cl|STICK}}(1, 2), {{Cl|STICK}}(0, 3); {{Cl|STICK}}(1, 3); "  "
 
   {{Cl|PRINT}} "                  Buttons"
 
   {{Cl|PRINT}} "                  Buttons"
 
   {{Cl|FOR...NEXT|FOR}} i = 0 {{Cl|TO}} 4 * buttons - 1 {{Cl|STEP}} 4
 
   {{Cl|FOR...NEXT|FOR}} i = 0 {{Cl|TO}} 4 * buttons - 1 {{Cl|STEP}} 4
     {{Cl|PRINT}} {{Cl|STRIG}}(i); {{Cl|STRIG}}(i + 1);
+
     {{Cl|PRINT}} {{Cl|STRIG}}(i); {{Cl|STRIG}}(i + 1); {{Cl|CHR$}}(219);
 
   {{Cl|NEXT}}
 
   {{Cl|NEXT}}
 
   {{Cl|PRINT}}
 
   {{Cl|PRINT}}
 
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" '' ''
 
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" '' ''
 
{{CodeEnd}}
 
{{CodeEnd}}
 +
: ''Explanation:'' Each axis on the first controller found is either STICK(0, n) or STICK(1, n) with n increasing when necessary.
 
{{OutputStart}}
 
{{OutputStart}}
 
Number of input devices found = 3
 
Number of input devices found = 3
Line 78: Line 81:
  
  
   X   Main   Y        Slider        Z-axis       POV
+
   X   Main     Y         Slider         Z-axis           POV
  127       127         254          127         127
+
  127           127           254          127           127  127
 
                       Buttons
 
                       Buttons
-0 -1 0  0 0  0 0  0 0  0 0  0 0  0 0  0 0  0  
+
-0 -1 0  0 0  0 0  0 0  0 0  0 0  0 0  0 0  0
 
{{OutputEnd}}
 
{{OutputEnd}}
 +
: ''Note:'' A Sidewinder Precision Pro requires that pins 2 and 7 (blue and purple) be connected together for digital USB recognition.
 +
  
 
''See also:''  
 
''See also:''  

Latest revision as of 13:11, 10 February 2021

The STICK function returns the directional axis coordinate move of game port (&H201) joystick or USB controller devices.


Syntax

coordinate_move% = STICK(direction%)


QB64 Syntax

coordinate_move% = STICK(direction%[, axis_number%])


Description:

  • QB64 allows any number of coordinate pairs for more than two game device controllers. STICK will not read a mouse axis.
  • axis_number can be used as the next axis parameter for controllers with multiple axis using the SAME directional parameters.
  • The axis_number 1 can be omitted for the main stick column and row parameter reads.
  • Point of view "hats" also have 2 axis. Slide, turn or twist controls have one. The device determines the order of the axis.
  • Returns coordinate values from 1 to 254. QBasic only returned values from 1 to 200.
  • STICK(0) is required to get values from the other STICK functions. Always read it first!

STICK(0) returns the column coordinate of device 1. Enables reads of the other STICK values. STICK(1) returns row coordinate of device 1. STICK(2) returns column coordinate of device 2. (second joystick if used) STICK(3) returns row coordinate of device 2 if used. (QBasic maximum was 2 controllers) STICK(4) returns column coordinate of device 3. (other joysticks if used in QB64 only!) STICK(5) returns row coordinate of device 3 if used.

  • QB64 allows more joysticks by extending the numbers in pairs like device 3 above. EX: STICK(6): STICK(7) 'device 4
  • QB64 allows a dual stick to be read using the same first parameters and 2 as the second parameter. EX: STICK(0, 2)
  • There will not be an error if you try to read too many device axis or buttons!


Example 1: Displays the input from 3 joysticks, all with dual sticks and 3 buttons.

DO: _LIMIT 10 LOCATE 1, 1 PRINT "JOY1: STICK"; STICK(0); STICK(1); STICK(0, 2); STICK(1, 2);_ "STRIG"; STRIG(0); STRIG(1); STRIG(4); STRIG(5); STRIG(8); STRIG(9) PRINT "JOY2: STICK"; STICK(2); STICK(3); STICK(2, 2); STICK(3, 2);_ "STRIG"; STRIG(2); STRIG(3); STRIG(6); STRIG(7); STRIG(10); STRIG(11) PRINT "JOY3: STICK"; STICK(4); STICK(5); STICK(4, 2); STICK(5, 2);_ "STRIG"; STRIG(0, 3); STRIG(1, 3); STRIG(4, 3); STRIG(5, 3); STRIG(8, 3); STRIG(9, 3) LOOP UNTIL INKEY$ > ""

Explanation: Notice the extra QB64 only parameters used to cater for the 2nd stick and the buttons of the 3rd joystick.


Example 2: Displays the Sidewinder Precision Pro Stick, Slider, Z Axis, and Hat Point of View.

SCREEN 12 d = _DEVICES PRINT "Number of input devices found ="; d FOR i = 1 TO d PRINT _DEVICE$(i) buttons = _LASTBUTTON(i) PRINT "Buttons:"; buttons NEXT DO: _LIMIT 50 LOCATE 10, 1 PRINT " X Main Y Slider Z-axis POV" PRINT STICK(0, 1), STICK(1, 1), STICK(0, 2), STICK(1, 2), STICK(0, 3); STICK(1, 3); " " PRINT " Buttons" FOR i = 0 TO 4 * buttons - 1 STEP 4 PRINT STRIG(i); STRIG(i + 1); CHR$(219); NEXT PRINT LOOP UNTIL INKEY$ <> ""

Explanation: Each axis on the first controller found is either STICK(0, n) or STICK(1, n) with n increasing when necessary.

Number of input devices found = 3 [KEYBOARD][BUTTON]] Buttons: 512 [MOUSE][BUTTON][AXIS][WHEEL] Buttons: 3 [CONTROLLER][[NAME][Microsoft Sidewinder Precision Pro (USB)]][BUTTON][AXIS] Buttons: 9 X Main Y Slider Z-axis POV 127 127 254 127 127 127 Buttons -0 -1 █ 0 0 █ 0 0 █ 0 0 █ 0 0 █ 0 0 █ 0 0 █ 0 0 █ 0 0 █

Note: A Sidewinder Precision Pro requires that pins 2 and 7 (blue and purple) be connected together for digital USB recognition.


See also:



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page