Pressing keys to make stuff happen

Everything related to BASIC version 1.x (Oric 1 and Atmos) or HYPERBASIC (Telestrat).
Don't hesitate to give your small program samples, technical insights, or questions...
Post Reply
Chris
2nd Star Corporal
Posts: 29
Joined: Tue Jun 05, 2007 1:45 am
Location: Oregon, United States
Contact:

Pressing keys to make stuff happen

Post by Chris » Wed Jun 06, 2007 1:45 pm

Say I'm making a title screen that says "Press space to start." How would I make it so that if I press space, the screen goes CLS and starts my game (i.e., you can actually play a game now that you've pressed space.) Same for enter, and left space, and right space, up down left & right? Once I know this, I'll be set for at least a few days ;)

User avatar
Pengwin
Pilot Officer
Posts: 67
Joined: Sun Jan 07, 2007 11:03 pm
Location: Scotland
Contact:

Post by Pengwin » Wed Jun 06, 2007 8:46 pm

There are 2 ways to do this. If you just want the program to pause until space is pressed, then this would suffice:

Code: Select all

100 PRINT "Press SPACE to continue"
110 REPEAT
120 GET A$
130 UNTIL A$=" "
140 CLS
150 REM ... Rest of game
if you want the front screen to animate something whilst waiting for the user to play you could try something like this:

Code: Select all

100 PRINT "Press SPACE to continue"
110 REPEAT
120 REM ..Animation code here
200 UNTIL KEY$=" "
210 CLS
220 REM ... Rest of game
if you choose the first method (without animation) and don't really care what key people press, it could be shortened to:

Code: Select all

100 PRINT "Press any key to continue"
110 GET A$
140 CLS
150 REM ... Rest of game

User avatar
Pengwin
Pilot Officer
Posts: 67
Joined: Sun Jan 07, 2007 11:03 pm
Location: Scotland
Contact:

Post by Pengwin » Wed Jun 06, 2007 8:50 pm

Just to re-iterate, these are the definitions from the Oric manual

GET (example GET A$)
Strobes the keyboard and waits until a key is pressed.
KEY$ (example X$=KEY$)
Strobes keyboard. Continues execution, whether or not a key has been pressed. X$ contains value of any key pressed.

Chris
2nd Star Corporal
Posts: 29
Joined: Tue Jun 05, 2007 1:45 am
Location: Oregon, United States
Contact:

Post by Chris » Thu Jun 07, 2007 12:01 am

Thanks. I was looking through the manual, but I couldn't find anything like that. I did see "strobes keyboard", though, but I don't know what that means.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests