ON STRIG(n): Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 12: Line 12:
* The statement sends the procedure to a line number, line label or [[SUB]] procedure when a button event occurs.
* The statement sends the procedure to a line number, line label or [[SUB]] procedure when a button event occurs.


 
=== QBasic/QuickBASIC ===
==QBasic/QuickBASIC==
* In QBasic, value of ''n'' could only be a number from 0 to 3 only as it could only monitor 2 joystick buttons and 2 joysticks.
* In QBasic, value of ''n'' could only be a number from 0 to 3 only as it could only monitor 2 joystick buttons and 2 joysticks.


Line 32: Line 31:
a$ = "[STRIG 0 EVENT]"
a$ = "[STRIG 0 EVENT]"
{{Cl|FOR...NEXT|FOR}} x = 1 {{Cl|TO}} {{Cl|LEN}}(a$)
{{Cl|FOR...NEXT|FOR}} x = 1 {{Cl|TO}} {{Cl|LEN}}(a$)
     {{Cl|PRINT}} {{Cl|MID$}}(a$, x, 1);
     {{Cl|PRINT}} {{Cl|MID$ (function)|MID$}}(a$, x, 1);
     {{Cl|_DELAY}} 0.02
     {{Cl|_DELAY}} 0.02
{{Cl|NEXT}}
{{Cl|NEXT}}
Line 62: Line 61:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [[STRIG ]], [[STICK]] {{text|(functions)}}
* [[STRIG ]], [[STICK]]
* [[STRIG(n)]] {{text|(statement)}}
* [[STRIG(n)]]
* [[_DEVICES]], [[_DEVICE$]], [[_LASTBUTTON]]
* [[_DEVICES]], [[_DEVICE$]], [[_LASTBUTTON]]
 
* [[Wikipedia:Analog stick|Single and Dual Stick Controllers]]
 
===External links===
* [http://en.wikipedia.org/wiki/Analog_stick Single and Dual Stick Controllers]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 16:31, 14 June 2024

The ON STRIG(n) statement is an event procedure that directs program flow upon the press of a specified joystick button.


Syntax

ON STRIG(buttonFunction) GOSUB {lineNumber|lineLabel}
ON STRIG(buttonFunction[, joystickNumber]) {GOSUB {lineNumber|lineLabel} | SUBprocedure}


  • In QB64 the value can be any button function number with any number of joysticks. See STRIG and STICK for parameters.
  • There are two buttonFunction for each button. The even numbered function is always the event of any press since last read.
  • The statement sends the procedure to a line number, line label or SUB procedure when a button event occurs.

QBasic/QuickBASIC

  • In QBasic, value of n could only be a number from 0 to 3 only as it could only monitor 2 joystick buttons and 2 joysticks.


Examples

Example 1: Reading a STRIG event to do something in a GOSUB procedure.

ON STRIG(0) GOSUB 10
STRIG(0)ON

DO
    PRINT ".";
    _LIMIT 30
LOOP UNTIL INKEY$ <> ""
END

10
a$ = "[STRIG 0 EVENT]"
FOR x = 1 TO LEN(a$)
    PRINT MID$(a$, x, 1);
    _DELAY 0.02
NEXT
RETURN


Example 2: Displays any number of game pad or joystick device button presses.

FOR j = 1 TO 256
    FOR b = 1 TO 256
        ON STRIG((b - 1) * 4, j) JoyButton (j - 1) * 256 + b - 1
    NEXT
NEXT
STRIG ON

DO
    PRINT ".";
    _LIMIT 30
LOOP UNTIL INKEY$ <> ""
END

SUB JoyButton (js AS LONG)
PRINT "Joystick #"; js \ 256 + 1; "button #"; (js AND 255) + 1; "pressed!"
END SUB
Explanation: Up to 256 controllers can be used in QB64 with many buttons to read.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link