Jump to content
IGNORED

inkey$ command is pissing me off


Recommended Posts

i am currently trying to make a text adventure version of Bioshock. unfortunately, using Inkey$ or the IF command leads to a hopeless loop.

 

example:

 

26 input a$

27 let a$=inkey$

28 if a$="" then goto 31 (or if inkey$="" then goto 31

31 print "you step out of the Bathysphere and take the radio"

29 if inkey$<>="" (or if a$<>="") then goto 32

32 print "the splicer tears out your stomach":end

 

simple right? no. upon inputting an answer, the game loops uselessly. the second option is all that can be selected with the first nowhere to be seen.

 

please help

Edited by Ranger03
Link to comment
Share on other sites

Nearly every BASIC has a command to get a key from the keyboard, but almost none of them wait for a response before proceeding.

 

You need to do something like this:

 

10 A$=INKEY$:IF A$="" THEN 10

 

Many computers of that era don't have INKEY$, but the logic is the same:

Commodore BASIC:

10 GET A$:IF A$="" THEN 10

 

TI BASIC:

10 CALL KEY(0,K,S)

20 IF S=0 THEN 10

 

TI Extended BASIC:

10 CALL KEY(0,K,S)::IF S=0 THEN 10

 

I believe Applesoft actually waits for a keypress so it doesn't need the IF check.

Link to comment
Share on other sites

I guess I have to ask, what do uou want the player to do?

 

Line 26 is your "pause" as Input will wait for you to type anything and/or press Enter. It shoukd sit there until Enter is pressed.

 

You turn the string A$ into an Inkey$. Inkey$ typically just looks for a key press, so not sure why you have that in there if you have Input. With Input you could have it check for anything typed. So, using something like

 

28 IF A$="GET RADIO" THEN 31

 

You could add in other potential entries as well.

 

In your example, line 31 (the "good" outcome) will immediately go to 32, where the splicer gets you. If your example is what you are doing, you'd need to steer the player to another set of lines away from the dreaded "end game" of 32.

 

I don't see a loop. If you press just Enter on Line 26 (which produces a null or "blank" response), you'll get the Radio result but then the splicer gets you. If you typed anything into 26 and pressed Enter, Inkey$ sees whatever you typed and goes straight to the splicer. Either way, the result ends the program.

 

It looks to me like you want some response as there are two outcomes. Something like this?

 

10 print"You are sitting in the chair of the bathesphere. Outside the viewport you see a radio on a table. What do you do?"

 

20 print "Press G to GET RADIO or O to OPEN HATCH"

 

30 A$=Inkey$

 

40 if A$="" then 30

 

42 if A$="G" then 50

 

44 if A$="O" then 60

 

46 Goto 60

 

50 Print"You exit the bathesphere and grab the radio. Behind you there is a sound of rending steel and high pitched dragging of metal, like a knife on a chalkboard".

 

52 Goto (whatever is next in the story)

 

60 Print" As you sit up and just open the door, a dusty smell enters your nostrils. As you stand there to take in the different atmosphere, the metal above you splits open and a dark shape drops on you. The last thing you see is a pool of your own blood running through the grate in the floor as you collapse"

 

62 Print"Game Over"

 

64 End

 

Line 30 will watch for a key to be pressed. If nothing is pressed, Line 40 will pop back to 30 to check again.

 

Lines 42 and 44 will look for specific key presses and will go to their respective spot. 46, theorhetically, will only be gotten to if a key is pressed (going past 30) but is NOT G or O.

 

50 is the good result where the player exits the bathesphere to grab the radio, which shpuld move the player to the next thing to do (possibly run like heck or face the splicer).

 

60 is the bad result, where the player just pops the door but doesn't move out of the way of the splicer. The program ends.

 

Is that what you are looking for?

 

Note I use Tandy Extended Color Basic, so command structure may vary.

Edited by Gamemoose
  • Like 2
Link to comment
Share on other sites

I guess I have to ask, what do uou want the player to do?

 

Line 26 is your "pause" as Input will wait for you to type anything and/or press Enter. It shoukd sit there until Enter is pressed.

 

You turn the string A$ into an Inkey$. Inkey$ typically just looks for a key press, so not sure why you have that in there if you have Input. With Input you could have it check for anything typed. So, using something like

 

28 IF A$="GET RADIO" THEN 31

 

You could add in other potential entries as well.

 

In your example, line 31 (the "good" outcome) will immediately go to 32, where the splicer gets you. If your example is what you are doing, you'd need to steer the player to another set of lines away from the dreaded "end game" of 32.

 

I don't see a loop. If you press just Enter on Line 26 (which produces a null or "blank" response), you'll get the Radio result but then the splicer gets you. If you typed anything into 26 and pressed Enter, Inkey$ sees whatever you typed and goes straight to the splicer. Either way, the result ends the program.

 

It looks to me like you want some response as there are two outcomes. Something like this?

 

10 print"You are sitting in the chair of the bathesphere. Outside the viewport you see a radio on a table. What do you do?"

 

20 print "Press G to GET RADIO or O to OPEN HATCH"

 

30 A$=Inkey$

 

40 if A$="" then 30

 

42 if A$="G" then 50

 

44 if A$="O" then 60

 

46 Goto 60

 

50 Print"You exit the bathesphere and grab the radio. Behind you there is a sound of rending steel and high pitched dragging of metal, like a knife on a chalkboard".

 

52 Goto (whatever is next in the story)

 

60 Print" As you sit up and just open the door, a dusty smell enters your nostrils. As you stand there to take in the different atmosphere, the metal above you splits open and a dark shape drops on you. The last thing you see is a pool of your own blood running through the grate in the floor as you collapse"

 

62 Print"Game Over"

 

64 End

 

Line 30 will watch for a key to be pressed. If nothing is pressed, Line 40 will pop back to 30 to check again.

 

Lines 42 and 44 will look for specific key presses and will go to their respective spot. 46, theorhetically, will only be gotten to if a key is pressed (going past 30) but is NOT G or O.

 

50 is the good result where the player exits the bathesphere to grab the radio, which shpuld move the player to the next thing to do (possibly run like heck or face the splicer).

 

60 is the bad result, where the player just pops the door but doesn't move out of the way of the splicer. The program ends.

 

Is that what you are looking for?

 

Note I use Tandy Extended Color Basic, so command structure may vary.

Yes, but i am hoping to shrink the program to fit within 16k or 48k. the majority of the program is simple text with few choices. a few REM statements are peppered in for newbies and for extra info

Link to comment
Share on other sites

INKEY will return the value of whatever is being currently pressed. The way to use it is shown above in post #5.

 

What version of BASIC are you using. I have a pretty good implementation in Tandy Model 100 BASIC.

 

 

Say you have a static last of keypresses that are allowed. Define them as a single string variable

 

S$="Q"+CHR$(28)+CHR$(29)+CHR$(31)+CHR$(30)+CHR$(70)+CHR$(102)+CHR$(32)+CHR$(13)

 

 

Then on this next line, all the magic happens.

 

ON INSTR(1,S$,INKEY$) GOTO 3200,3500,3520,3540,3560,3600,3600,4000,4000

 

 

The ON function basically allows a GOTO where it will branch to a line number from a list based on what value is passed in. In my example, CHR$(28) is the second character in the string. If you press down that key, it will find it in S$ as the second char, and branch to the second line in the GOTO list, 3500.

Link to comment
Share on other sites

The main reason(s) to use INKEY$ are avoiding the INPUT prompt (?) and accepting input with characters that cause INPUT to crash (usually the comma).

 

If you want to use INKEY$ for the latter, do something like this (pseudo Sinclair BASIC off the top of my head):

 

9000 let a$ = inkey$

9001 if a$ ="" then goto 9000

9002 if a$ = chr(118) then goto 9099

9003 rem 118 is the sinclair newline/return

9003 rem other if statements to break out of the loop

9010 let p$ = p$ + a$

9011 goto 9000

9099 return

 

Call it (where you need to accept input) with:

 

100 gosub 9000

105 rem parse p$ however you'd like

 

That said, writing a parser to fit in 16K is going to be a challenge. You may want to write the parser as a subroutine that returns simpler versions of the input. Something along these lines:

  • split the input on non-alpha characters (space, probably)
  • assume the first word is a verb
  • map verbs to hexadecimal values: get=01, put=02, open=03, close=04, drop=05, etc, up to FF
  • assume the second word is a noun
  • map nouns to hexadecimal values, up to FF
  • append the noun value to the verb value, so you have a string like "A90E"
  • return from the subroutine
  • compare result to the acceptable verb/noun values: IF $v = "FE01" THEN [do something]
Link to comment
Share on other sites

Nearly every BASIC has a command to get a key from the keyboard, but almost none of them wait for a response before proceeding.

 

You need to do something like this:

 

10 A$=INKEY$:IF A$="" THEN 10

 

Many computers of that era don't have INKEY$, but the logic is the same:

Commodore BASIC:

10 GET A$:IF A$="" THEN 10

 

TI BASIC:

10 CALL KEY(0,K,S)

20 IF S=0 THEN 10

 

TI Extended BASIC:

10 CALL KEY(0,K,S)::IF S=0 THEN 10

 

I believe Applesoft actually waits for a keypress so it doesn't need the IF check.

i actually made a 1k version for the vic 20 on the blog page

Link to comment
Share on other sites

i am using sinclair basic. there is no way i can fit that string into 48k. anyway, i am using input for now because the game is meant to be short. episodic so to speak. i will be cutting half of the game because 48k is not enough memory

A stock Spectrum has a reasonable amount of RAM in BASIC so there should be no way you're filling it up with that small block of commands unless you're not being sensible about how the game is programmed and have bespoke code for every situation in the game rather than just having one central command parser that's fed data about locations, objects and so on.

 

Reading up on how text adventures work is probably a good idea if the latter is true...

  • Like 1
Link to comment
Share on other sites

For kicks I looked up an Infocom title and it was available for the Spectrum. If that's the case, you can possibly use the Inform development tool that will allow you to create text adventures (or "interactive fiction") and then port it to practically any system the Z Interpreter (allows you to use Infocom style story files) is available on. I saw there is one for Spectrum. How well it runs, I dunno.

 

So if you wanted to skip the BASIC to create the parser and world, you csn use this and focus on creating the world, items, people, interactions, etc. Of course, you'd have to wrap your brain around Inform's natural language "code", but it doesn't look too evil.

  • Like 1
Link to comment
Share on other sites

Both Quill and The Graphic Adventure Creator existed for the 48K ZX Spectrum.

 

A text adventure parser of the verb + noun style doesn't take very much memory. It is the map, the objects, the descriptions, the special actions that will consume memory. Several text adventures were written for 16K Spectrum or even other systems with far less memory, like an unexpanded VIC-20. Of course the adventure game would be rather small but it is well within reach.

Link to comment
Share on other sites

I guess I have to ask, what do uou want the player to do?

 

Line 26 is your "pause" as Input will wait for you to type anything and/or press Enter. It shoukd sit there until Enter is pressed.

 

You turn the string A$ into an Inkey$. Inkey$ typically just looks for a key press, so not sure why you have that in there if you have Input. With Input you could have it check for anything typed. So, using something like

 

28 IF A$="GET RADIO" THEN 31

 

You could add in other potential entries as well.

 

In your example, line 31 (the "good" outcome) will immediately go to 32, where the splicer gets you. If your example is what you are doing, you'd need to steer the player to another set of lines away from the dreaded "end game" of 32.

 

I don't see a loop. If you press just Enter on Line 26 (which produces a null or "blank" response), you'll get the Radio result but then the splicer gets you. If you typed anything into 26 and pressed Enter, Inkey$ sees whatever you typed and goes straight to the splicer. Either way, the result ends the program.

 

It looks to me like you want some response as there are two outcomes. Something like this?

 

10 print"You are sitting in the chair of the bathesphere. Outside the viewport you see a radio on a table. What do you do?"

 

20 print "Press G to GET RADIO or O to OPEN HATCH"

 

30 A$=Inkey$

 

40 if A$="" then 30

 

42 if A$="G" then 50

 

44 if A$="O" then 60

 

46 Goto 60

 

50 Print"You exit the bathesphere and grab the radio. Behind you there is a sound of rending steel and high pitched dragging of metal, like a knife on a chalkboard".

 

52 Goto (whatever is next in the story)

 

60 Print" As you sit up and just open the door, a dusty smell enters your nostrils. As you stand there to take in the different atmosphere, the metal above you splits open and a dark shape drops on you. The last thing you see is a pool of your own blood running through the grate in the floor as you collapse"

 

62 Print"Game Over"

 

64 End

 

Line 30 will watch for a key to be pressed. If nothing is pressed, Line 40 will pop back to 30 to check again.

 

Lines 42 and 44 will look for specific key presses and will go to their respective spot. 46, theorhetically, will only be gotten to if a key is pressed (going past 30) but is NOT G or O.

 

50 is the good result where the player exits the bathesphere to grab the radio, which shpuld move the player to the next thing to do (possibly run like heck or face the splicer).

 

60 is the bad result, where the player just pops the door but doesn't move out of the way of the splicer. The program ends.

 

Is that what you are looking for?

 

Note I use Tandy Extended Color Basic, so command structure may vary.

Just tried your program. very useful. too bad my memory sucks lol

Link to comment
Share on other sites

I guess I have to ask, what do uou want the player to do?

 

Line 26 is your "pause" as Input will wait for you to type anything and/or press Enter. It shoukd sit there until Enter is pressed.

 

You turn the string A$ into an Inkey$. Inkey$ typically just looks for a key press, so not sure why you have that in there if you have Input. With Input you could have it check for anything typed. So, using something like

 

28 IF A$="GET RADIO" THEN 31

 

You could add in other potential entries as well.

 

In your example, line 31 (the "good" outcome) will immediately go to 32, where the splicer gets you. If your example is what you are doing, you'd need to steer the player to another set of lines away from the dreaded "end game" of 32.

 

I don't see a loop. If you press just Enter on Line 26 (which produces a null or "blank" response), you'll get the Radio result but then the splicer gets you. If you typed anything into 26 and pressed Enter, Inkey$ sees whatever you typed and goes straight to the splicer. Either way, the result ends the program.

 

It looks to me like you want some response as there are two outcomes. Something like this?

 

10 print"You are sitting in the chair of the bathesphere. Outside the viewport you see a radio on a table. What do you do?"

 

20 print "Press G to GET RADIO or O to OPEN HATCH"

 

30 A$=Inkey$

 

40 if A$="" then 30

 

42 if A$="G" then 50

 

44 if A$="O" then 60

 

46 Goto 60

 

50 Print"You exit the bathesphere and grab the radio. Behind you there is a sound of rending steel and high pitched dragging of metal, like a knife on a chalkboard".

 

52 Goto (whatever is next in the story)

 

60 Print" As you sit up and just open the door, a dusty smell enters your nostrils. As you stand there to take in the different atmosphere, the metal above you splits open and a dark shape drops on you. The last thing you see is a pool of your own blood running through the grate in the floor as you collapse"

 

62 Print"Game Over"

 

64 End

 

Line 30 will watch for a key to be pressed. If nothing is pressed, Line 40 will pop back to 30 to check again.

 

Lines 42 and 44 will look for specific key presses and will go to their respective spot. 46, theorhetically, will only be gotten to if a key is pressed (going past 30) but is NOT G or O.

 

50 is the good result where the player exits the bathesphere to grab the radio, which shpuld move the player to the next thing to do (possibly run like heck or face the splicer).

 

60 is the bad result, where the player just pops the door but doesn't move out of the way of the splicer. The program ends.

 

Is that what you are looking for?

 

Note I use Tandy Extended Color Basic, so command structure may vary.

I got it to work! thanks

Link to comment
Share on other sites

I am beginning to doubt the fact that i can pull this off. I mean it's a great game sure, but i don't see myself being able to do so at the moment. At best, maybe i can do 1 part over 3 weeks, then focus on the next while the first section is tested by the players, fix those problems and finally have the second part to myself. like Half life 2's episodes

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...