1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 15:00:38 +00:00
QB64-PE/internal/help/ON_STRIG(n).txt

75 lines
2.4 KiB
Plaintext
Raw Normal View History

2019-04-15 01:15:33 +00:00
The [[ON STRIG(n)]] statement is an event procedure that directs program flow upon the press of a specified joystick button.
{{PageSyntax}}
2019-04-15 01:15:33 +00:00
: '''ON STRIG'''({{Parameter|buttonFunction}}) [[GOSUB]] {{{Parameter|lineNumber}}|{{Parameter|lineLabel}}}
2019-04-15 01:15:33 +00:00
: '''ON STRIG'''({{Parameter|buttonFunction}}[, {{Parameter|joystickNumber}}]) {[[GOSUB]] {{{Parameter|lineNumber}}|{{Parameter|lineLabel}}} | [[SUB]]procedure}
2019-04-15 01:15:33 +00:00
* In '''QB64''' the value can be any button function number with any number of joysticks. See [[STRIG]] and [[STICK]] for parameters.
* There are two {{Parameter|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==
2019-04-15 01:15:33 +00:00
* 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.
2019-04-15 01:15:33 +00:00
{{PageExamples}}
''Example 1:'' Reading a STRIG event to do something in a [[GOSUB]] procedure.
{{CodeStart}} '' ''
{{Cl|ON STRIG(n)|ON STRIG}}(0) {{Cl|GOSUB}} 10
{{Cl|STRIG(n)|STRIG}}(0)ON
{{Cl|DO...LOOP|DO}}
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} ".";
{{Cl|_LIMIT}} 30
2019-04-15 01:15:33 +00:00
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> ""
{{Cl|END}}
10
2019-04-15 01:15:33 +00:00
a$ = "[STRIG 0 EVENT]"
{{Cl|FOR...NEXT|FOR}} x = 1 {{Cl|TO}} {{Cl|LEN}}(a$)
{{Cl|PRINT}} {{Cl|MID$}}(a$, x, 1);
{{Cl|_DELAY}} 0.02
{{Cl|NEXT}}
{{Cl|RETURN}} '' ''
{{CodeEnd}}
''Example 2:'' Displays any number of game pad or joystick device button presses.
{{CodeStart}}
{{Cl|FOR...NEXT|FOR}} j = 1 {{Cl|TO}} 256
{{Cl|FOR...NEXT|FOR}} b = 1 {{Cl|TO}} 256
{{Cl|ON STRIG(n)|ON STRIG}}((b - 1) * 4, j) JoyButton (j - 1) * 256 + b - 1
{{Cl|NEXT}}
{{Cl|NEXT}}
{{Cl|STRIG(n)|STRIG}} ON
{{Cl|DO...LOOP|DO}}
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} ".";
{{Cl|_LIMIT}} 30
2019-04-15 01:15:33 +00:00
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> ""
{{Cl|END}}
{{Cl|SUB}} JoyButton (js {{Cl|AS}} {{Cl|LONG}})
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} "Joystick #"; js \ 256 + 1; "button #"; (js {{Cl|AND (boolean)|AND}} 255) + 1; "pressed!"
{{Cl|END SUB}} '' ''
{{CodeEnd}}
:''Explanation:'' Up to 256 controllers can be used in QB64 with many buttons to read.
2019-04-15 01:15:33 +00:00
{{PageSeeAlso}}
* [[STRIG ]], [[STICK]] {{text|(functions)}}
* [[STRIG(n)]] {{text|(statement)}}
* [[_DEVICES]], [[_DEVICE$]], [[_LASTBUTTON]]
2019-04-15 01:15:33 +00:00
===External links===
* [http://en.wikipedia.org/wiki/Analog_stick Single and Dual Stick Controllers]
2019-04-15 01:15:33 +00:00
{{PageNavigation}}
<