Q(uick)BASIC Function: STRIG

Quick View

STRIG

A device I/O function that returns the status of a specified joystick trigger

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • STRIG(n%)
Description/Parameter(s)
n% A value that specifies a joystick status condition:
n%Condition
0Lower joystick A trigger was pressed since last STRIG(0)
1Lower joystick A trigger is currently pressed
2Lower joystick B trigger was pressed since last STRIG(2)
3Lower joystick B trigger is currently pressed
4Upper joystick A trigger was pressed since last STRIG(4)
5Upper joystick A trigger is currently pressed
6Upper joystick B trigger was pressed since last STRIG(6)
7Upper joystick B trigger is currently pressed
STRIG returns -1 if the condition is true, 0 otherwise.
Example
PRINT "Press Esc to exit." DO IF STRIG(0) OR INKEY$ = CHR$(27) THEN EXIT DO LOOP DO BEEP 'BEEP while trigger A is pressed. LOOP WHILE STRIG(1)
Syntax
  • STRIG(n)
Description/Parameter(s)

The STRIG function is used to test the joystick trigger status. In previous versions of BASIC, the statement STRIG ON enables testing of the joystick triggers; STRIG OFF disables joystick trigger testing. QuickBASIC ignores STRIG ON and STRIG OFF statements--the statements are provided for compatibility with earlier versions.

The numeric expression n is an unsigned integer in the range 0-7, indicating the joystick and trigger to check. The following list describes the values returned by the STRIG(n) function for different values of n:

Argument Button Joystick Value Returned
0 lower A -1 = pressed since last STRIG(0) call, 0 = not
1 lower A -1 = currently down, 0 = not
2 lower B -1 = pressed since last STRIG(2) call, 0 = not
3 lower B -1 = currently down, 0 = not
4 upper A -1 = pressed since last STRIG(4) call, 0 = not
5 upper A -1 = currently down, 0 = not
6 upper B -1 = pressed since last STRIG(6) call, 0 = not
7 upper B -1 = currently down, 0 = not

You can also use event trapping to get information from the joystick by using the ON STRIG statement. You cannot use the STRIG function inside a joystick event trap because the event that caused the trap is destroyed.

Differences from BASICA

  • If you are compiling from the BC command line, you must use the /V or /W option if a program contains a STRIG statement.
Example

The following example illustrates STRIG:

' *** STRIG function programming example *** ' Do not attempt to run this program without a joystick installed ' ' Wait for trigger A to be pressed. DO GotATrig = STRIG(0) LOOP UNTIL GotATrig ' As long as trigger A is down, beep. DO GotATrig = STRIG(1) BEEP LOOP WHILE GotATrig
Syntax
  • STRIG(n%)
Description/Parameter(s)

Usage Notes

  • n% is an integer between 0 and 7 that indicates the joystick and trigger to check. The following list describes the values returned by the STRIG function for different values of n%:
    ArgumentValue Returned
    0-1 if the lower trigger on joystick A was pressed since the last STRIG(0) call, 0 if not.
    1-1 if the lower trigger on joystick A is currently down, 0 if not.
    2-1 if the lower trigger on joystick B was pressed since the last STRIG(2) call, 0 if not.
    3-1 if the lower trigger on joystick B is currently down, 0 if not.
    4-1 if the upper trigger on joystick A was pressed since the last STRIG(4) call, 0 if not.
    5-1 if the upper trigger on joystick A is currently down, 0 if not.
    6-1 if the upper trigger on joystick B was pressed since the last STRIG(6) call, 0 if not.
    7-1 if the upper trigger on joystick B is currently down, 0 if not.
  • See ON STRIG for information on joystick-event trapping. You cannot use the STRIG function inside a joystick event trap, because the trigger information used by the STRIG function will not be available for ON STRIG.
  • In previous versions of BASIC, the statement STRIG ON enabled testing of the joystick triggers; STRIG OFF disabled joystick trigger testing. The current version of BASIC ignores STRIG ON and STRIG OFF statements. (The old STRIG ON and STRIG OFF should not be confused with the STRIG(n%) ON, STRIG(n%) OFF, and STRIG(n%) STOP statements. The STRIG(n%) statements enable, disable, and inhibit trapping of joystick events.)
Example

This example uses the EVENT and STRIG statements to enable joystick event trapping for two buttons on each of two joysticks. The ON STRIG statement passes control to an event-handling routine when a button is pressed. The STRIG function is used to determine which button was pressed, and the STICK function returns the position of both joysticks.

CLS 'Turn on event processing. EVENT ON 'Enable the upper and lower buttons on both joysticks. STRIG(0) ON 'Lower button, joystick A STRIG(2) ON 'Lower button, joystick B STRIG(4) ON 'Upper button, joystick A STRIG(6) ON 'Upper button, joystick B 'Set up joystick event processing for each button. ON STRIG(0) GOSUB JoyButtonHandler ON STRIG(2) GOSUB JoyButtonHandler ON STRIG(4) GOSUB JoyButtonHandler ON STRIG(6) GOSUB JoyButtonHandler LOCATE 22, 6 PRINT "Press a button on either joystick to see a complete joystick report." LOCATE 23, 20 PRINT "Press ANY keyboard key to end the program." 'Infinite loop waiting for a Joystick event or keyboard key input. DO LOOP WHILE INKEY$ = "" WrapItUp: CLS STRIG(0) OFF STRIG(2) OFF STRIG(4) OFF STRIG(6) OFF END JoyButtonHandler: 'Print a label on screen. LOCATE 10, 14: PRINT "Joystick A" LOCATE 10, 45: PRINT "Joystick B" LOCATE 22, 1: PRINT STRING$(80, 32) DO 'Button 1, Joystick A. IF STRIG(1) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 16, 10: PRINT "Button 1 is "; ButtonStatus$ EVENT ON 'Button 1, Joystick B. IF STRIG(3) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 16, 42: PRINT "Button 1 is "; ButtonStatus$ EVENT ON 'Button 2, Joystick A. IF STRIG(5) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 18, 10: PRINT "Button 2 is "; ButtonStatus$ EVENT ON 'Button 2, Joystick B. IF STRIG(7) THEN ButtonStatus$ = "DOWN" ELSE ButtonStatus$ = "UP " END IF EVENT OFF LOCATE 18, 42: PRINT "Button 2 is "; ButtonStatus$ EVENT ON GOSUB UpdateXY LOOP WHILE INKEY$ = "" RETURN WrapItUp UpdateXY: EVENT OFF LOCATE 12, 10: PRINT USING "X Position = ###"; STICK(0) LOCATE 14, 10: PRINT USING "Y Position = ###"; STICK(1) LOCATE 12, 42: PRINT USING "X Position = ###"; STICK(2) LOCATE 14, 42: PRINT USING "Y Position = ###"; STICK(3) EVENT ON RETURN