×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Joystick's in QBasic

Joystick's in QBasic

Joystick's in QBasic

(OP)
Does anyone have some simple code that can allow me to use a joystick to control my game in QBasic?  I know that's rather vague, but the whole idea isn't very complex so it doesn't really require a lot of explaining.  Thanks for any help.

RE: Joystick's in QBasic

Here is some sample code I made when I first learned to use the joystick in QB

CLS
SCREEN 12
10 'Begining
A% = INP(&H201)
LOCATE 1, 1: PRINT "Current:"
LOCATE 1, 9: PRINT A%
'OUT &H201, B%
LOCATE 2, 1: PRINT "Base:"
LOCATE 2, 6: PRINT PEEK(0)
X = PEEK(1)
IF PEEK(1) = 1 THEN F = PEEK(0) - A%
LOCATE 3, 1: PRINT "Final:"
LOCATE 3, 7: PRINT F
IF F = 16 THEN LOCATE 4, 1: PRINT "Button#1"
IF F = 32 THEN LOCATE 4, 1: PRINT "Button#2"
IF F = 64 THEN LOCATE 4, 1: PRINT "Button#3"
IF F = 48 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2"
IF F = 80 THEN LOCATE 4, 1: PRINT "Button#1 & Button#3"
IF F = 96 THEN LOCATE 4, 1: PRINT "Button#2 & Button#3"
IF F = 112 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2 & Button#3"
IF F = 128 THEN LOCATE 4, 1: PRINT "Button#4"
IF F = 144 THEN LOCATE 4, 1: PRINT "Button#1 & Button#4"
IF F = 160 THEN LOCATE 4, 1: PRINT "Button#2 & Button#4"
IF F = 176 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2 & Button#4"
IF F = 192 THEN LOCATE 4, 1: PRINT "Button#3 & Button#4"
IF F = 208 THEN LOCATE 4, 1: PRINT "Button#1 & Button#3 & Button#4"
IF F = 224 THEN LOCATE 4, 1: PRINT "Button#2 & Button#3 & Button#4"
IF F = 240 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2 & Button#3 &Button#4"
PRINT " "; SPACE$(40)
IF X = 0 THEN GOTO 20
IF X = 1 THEN GOTO 10
20 'Store A% Value
POKE 0, A%
POKE 1, 1
GOTO 10

RE: Joystick's in QBasic

(OP)
Hrmm...gave it a try but it didn't do anything.  Is there anything special I have to do with the joystick settings to get it to work?

RE: Joystick's in QBasic

The joystick you are using is it plugged into the game port or usb - I've used this code with three different joysticks and it works

(all joysticks I used run on the game port)

%, 2004

RE: Joystick's in QBasic

(OP)
I'm using one on the game port, (it configured in the windows setup) and then I have two joysticks wired in through the printer port.  None of them do anything.  I'll give it another go in the morning, but I'm not sure what to try.  Are you using Windows XP?  Or should that not make any difference?

RE: Joystick's in QBasic

Since you have a game port it should work.  Of course, qb has this [screen shot] in it's HELP Files:


CODE

+------------------ HELP: STICK Function QuickSCREEN
¦  QuickSCREEN      Details      Example   Contents
¦---------------------------------------------------
¦STICK - a device I/O function that returns the x
         and y coordinates of the two joysticks
¦                
¦Syntax          
¦  STICK(n)    
¦    > n, a numeric expression that has an unsigned
       integer value between 0 and 3, tells the STICK
       function which one of four possible joystick
       coordinate values to return (see Details)    
¦         
+-------------------------------- Untitled
¦stick      
¦           

Under the EXAMPLE link it has this:

CODE

STICK Function Programming Example

The following program prints the coordinates of joystick B:

'*** Programming example for STICK function ***
' Do not attempt to run this program unless a joystick is installed
TEMP = STICK(0)
PRINT STICK(2), STICK(3)
Does this help?
--MiggyD

RE: Joystick's in QBasic

Hey sandmann999,

Did any of this help?

RE: Joystick's in QBasic

(OP)
Sorry, forgot to get back to you.  No, unfortunately, none of the code did anything.  The STICK function as well as the other code didn't work with any of my joysticks in any port.  Could it be Windows XP?  If not, any other ideas?  Thanks.

RE: Joystick's in QBasic

You could always try visual basic  - the code is mostly the same - you just have to get used to using controls which is easy once you get the hang of - one of the first apps I made in vb was one that you controlled the mouse with the joystick - I made it on a windows 98 machine - and it still works on my xp machine - I think you would really enjoy vb comared to qb

%, 2004

RE: Joystick's in QBasic

Oh. XP. Yep, that could be a problem. Have you looked inside your system to see if it (the game card) is pnp?

If so, the port addressing may differ than what QB was ment for.

Sorry I can't help you out any further.  If you have a friend that has DOS or Win 9x/ME you can try the stick function.  Here's an example you can paste into a bas to try to determine if it's working or not:

CODE

CLS
PRINT "joystick A: "
PRINT "joystick B: "
PRINT : PRINT "Press any key to exit"
DO WHILE T$ = ""
    LOCATE 1, 13
    PRINT STICK(0), STICK(1)
    LOCATE 2, 13
    PRINT STICK(2), STICK(3)
    IF INKEY$ <> "" THEN T$ = "x"
LOOP
END

Good Luck,
--MiggyD

RE: Joystick's in QBasic

Poke & Peek are memory commands - the command peeks into a location in the bios to check the status of the joystick - with xp this is not allowed - xp disallows this - is it a security feature I beleive it is the same on 2k also

with vb the way this is done is through the driver interface - using what is called a windows api (Application Protocal Interface) the api commands are built into dll file(s) - so if you ever wondered the main reason for dll(s) this is it - with the windows api's they for the most part stay they same - the api used to get the joysticks input is in NT,95,98,2K,ME,XP so this is one excellent reason to use a language that can interface with the windows api(s) - examples are:

Visual Basic
Visual C++

%, 2004

RE: Joystick's in QBasic

(OP)
Got it to work in Windows 98.  (I have both 98 and XP on my computer).  It worked great, got a little dot to "fly" around the screen and shoot little bullets when I pressed the buttons.  The analogue feature of the STICK command is pretty cool.  Unfortunately, it doesn't work in XP and I'm not sure how to get it to.  Still cool though.

RE: Joystick's in QBasic

Glad to have helped.
--MiggyD

RE: Joystick's in QBasic

And some game pads get tricky and use both stick and strig 1 & 2 for a single controller...

I had a 6 button controll pad that did that...

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.

RE: Joystick's in QBasic

Sandmann,

I'm on winME and in the control panel there's an joy stick icon called "Game Options". Have you looked in there? (control panel?)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close