Asking the Player
The program asks whoever is using it, and does something different depending on the answer.
So far you decided what went in every box, back when you wrote the program. That means the program does the same thing every single time.
A real program asks the person using it.
Read an answer into a box
ASK "What is your name? " INTO name
SHOW "Hello, ", name
The first line shows the question and waits. Whatever the person types goes into the box
name. The second line reads that box.
Type Sam:
What is your name? Sam Hello, Sam
Now run the same program again, and type something else:
What is your name? Ada Hello, Ada
Nothing in the program changed between those two runs. You did. A program that asks gives a different answer every time, depending on who sits at the keyboard.
Every game leans on this. It is how a player plays instead of watching.
When it’s wrong, see why
- The greeting runs into the name, like
Hello,Ada. The space belongs inside the quotation marks, as"Hello, ". The comma joins and adds nothing, from Unit 3. - You get an empty greeting. Someone pressed Enter without typing anything, so the box holds nothing.
- The computer does not know the name. Check that the box you read is the box you filled.
What you’ve learnt
- Input lets a program read what someone types and keep it in a box.
- A program that asks gives a different result for a different answer, without a single line of it changing.
- That is the difference between watching and playing.
What’s next
You can ask for a name and greet it. But people often answer with a number, and you can add, compare and count numbers. In the next module, Working It Out, the program starts working things out from what the player types.
You can try this idea by asking for words to build a story in Meet BASIC. The lesson explains the Spectrum’s own syntax as you use it.