octave,
You stated that you simply wish to be able to press a key, 1 through 8, and have the text change to another text at this happenning. Also, you included that once the key is let off of, you do not want the text to clear from the screen, but to stay until another key is pressed.
To do this you need to make use of a variable. When a key is pressed, the variable is given a specific number,according to what key is pressed. As long as that variable includes that number, the text corresponding to the number will be displayed, until a different key is pressed and the variable is given another number. Study the code snippet below.
set display mode 800,600,32
sync on
sync rate 60
REM << sentence constants
`declare an array to fill with sentence constants, numbered 1 to 8
dim constants$(8)
`fill array with sentence constants
constants$(1) = "This is displaying because you pressed the number 1."
constants$(2) = "Hmm...you have pressed the number 2 key."
constants$(3) = "Well, they always say that the 3rd key is a charm."
constants$(4) = "Did you request for the number 4?"
constants$(5) = "5 is half of ten."
constants$(6) = "Yep, this is the number 6 key."
constants$(7) = "7 is an odd number, literally."
constants$(8) = "You made it to the number 8 key."
REM <<<<<<<<<<< main loop >>>>>>>>>>>>>
repeat
REM << fill variable 'number' with the number value of key pressed
`if key pressed is not a number, a value of 0 will be returned, else the value of the number will be returned
if inkey$() <> ""
number = val(inkey$())
`only print instructions until a key is pressed
endstartsentence = 1
endif
REM << print constant referenced by variable 'number'
`sentence will stay the same until another number between 1 and 8 is pressed
if endstartsentence = 1
if number => 1 and number =< 8
text 0,0,constants$(number)
else
text 0,0,"This is not a valid key. Please press a number key between 1 and 8."
endif
else
REM << print instructions to screen
text 0,0,"Press a number key between 1 and 8"
endif
sync
cls
until mouseclick() = 2
Remember, to make use of variables, which are the cornerstones of programming. Without variables, a useful program cannot be written. A variable is a slot of memory that holds a value. This value stays the same until you or your program changes its value. So, in this example, the variable
number does not change until another key is pressed, and the displaying sentence does not change until the variable changes.
+NanoBrain+