tabnewflax
New Member
Posts: 22
|
 |
« on: March 10, 2004, 08:13:24 AM » |
|
INPUT "1. Yes 2. No", choice SELECT CASE choice CASE 1 GOTO yes CASE 2 GOTO no END SELECT
That is just an example of my problem. So my problem is that you could just press ENTER or a digit except 1 and 2 to get to the next section in the game. Which kinda makes the game worthless.
How do I type so the only possible options is 1 and 2?
|
|
|
Logged
|
|
|
|
R@dioman
|
 |
« Reply #1 on: March 10, 2004, 08:18:00 AM » |
|
You can use CASE ELSE like so: Menu: INPUT "1 or 2", choice
SELECT CASE CASE 1 GOTO Yes CASE 2 GOTO No CASE ELSE PRINT "Select either 1 or 2 please" GOTO Menu END SELECT
|
|
|
Logged
|
|
|
|
Agamemnus
|
 |
« Reply #2 on: March 10, 2004, 01:47:26 PM » |
|
This is just the proverbial tip of the iceberg.
You can change your keyboard input in many ways:
*use a different input command, like I$ = INKEY$ or n% = INP(96). *error-check the answer by asking for a string, and then error-check it: get rid of leading/trailing spaces, etc. *You can use key/mouse-selection menus so there are no invalid answers.
You can find some things here: faq.qbasicnews.com
|
|
|
Logged
|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war." Visit www.neobasic.net to see rubbish in all its finest.
|
|
|
Mango
Wandering Guru
  
Posts: 360
|
 |
« Reply #3 on: March 11, 2004, 01:13:41 AM » |
|
This is just the proverbial tip of the barrel. Is it that or is it the proverbial tip of the iceberg??!!?? :-? :  :
|
|
|
Logged
|
|
|
|
Agamemnus
|
 |
« Reply #4 on: March 11, 2004, 01:40:48 AM » |
|
What are you talking about?
|
|
|
Logged
|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war." Visit www.neobasic.net to see rubbish in all its finest.
|
|
|
Plasma
|
 |
« Reply #5 on: March 11, 2004, 02:00:30 AM » |
|
Last edited by Agamemnus on Wed Mar 10, 2004 11:39 pm; edited 1 time in total
|
|
|
Logged
|
|
|
|
Agamemnus
|
 |
« Reply #6 on: March 11, 2004, 02:15:06 AM » |
|
Ok, I admit it.
Yeah.
It's iceberg.
|
|
|
Logged
|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war." Visit www.neobasic.net to see rubbish in all its finest.
|
|
|
Mac
|
 |
« Reply #7 on: March 14, 2004, 01:04:09 AM » |
|
Mac
|
|
|
Logged
|
|
|
|
Sumo Jo
|
 |
« Reply #8 on: March 14, 2004, 01:18:34 AM » |
|
|
|
|
Logged
|
|
|
|
Pyrodap
Senior Member
 
Posts: 166
|
 |
« Reply #9 on: March 14, 2004, 01:30:24 AM » |
|
Try this...
PRINT "PRESS EITHER 1 OR 2"
DO K$ = INKEY$ LOOP UNTIL K$ = "1" OR K$ = "2"
SELECT CASE K$ CASE "1" 'Code for 1 CASE "2" 'Code for 2 END SELECT
|
|
|
Logged
|
|
|
|
Moneo
|
 |
« Reply #10 on: March 14, 2004, 01:31:42 AM » |
|
So, tabnewflax, did Radioman's example solve your question, or do you further doubts? *****
|
|
|
Logged
|
|
|
|
Blitz
|
 |
« Reply #11 on: March 14, 2004, 06:55:29 AM » |
|
I think this is better coding practice. do input "Enter selection", ikey select case ikey case "1" print "You pressed 1" exit do case "2" print "You pressed 2" exit do case else print "Invalid option, try again" end select loop
|
|
|
Logged
|
oship me and i will give you lots of guurrls and beeea
|
|
|
TheBigBasicQ
|
 |
« Reply #12 on: March 14, 2004, 11:07:34 AM » |
|
Read the subject =P BTW You could try this if you have lot of code in each case: do input "Enter key ", ikey select case ikey case "1" CALL KEY1 exit do case "2" CALL KEY2 exit do case ... ... case else print "Invalid!!!" end select loop
|
|
|
Logged
|
|
|
|
Agamemnus
|
 |
« Reply #13 on: March 14, 2004, 01:45:32 PM » |
|
This is MUCH more sane: DO INPUT "Enter the !#$!@#$@#$ key already!!", ikey SELECT CASE ikey CASE "1": key1: EXIT DO CASE "2": key2: EXIT DO CASE ...... CASE ELSE: PRINT "INVALID!" END SELECT LOOP
|
|
|
Logged
|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war." Visit www.neobasic.net to see rubbish in all its finest.
|
|
|
Moneo
|
 |
« Reply #14 on: March 14, 2004, 09:50:51 PM » |
|
Ah, yes, I like Aga's example. It reads so much better. Some people may not like multiple statements on one line, but they sure make the code look nice. You can see the whole thing with one glance. *****
|
|
|
Logged
|
|
|
|
|