Collect User Input
00:00 The player should have the options to attack, heal, and run away. Three different options, and we need some sort of way for the user to input their decision of which of those options they want to choose, right? So, you could use numbers to do that.
You could say attack is
1, heal is
2, run away is
3. But for a text-based game, I have the feeling it’s maybe easier to understand if it’s something that they type in, some sort of text they type in. Let me draft this up.
00:47 And now I don’t really want them to have to type out the whole word. Something you may have seen around is I’m going to indicate that they should just put in the first letter of these different options.
If they type an
A, I’m going to take that to mean that they want to attack. If they type an
H, it’s going to mean that they want to heal. And if they type
R, it’s going to mean they want to run away.
So that’ll be my action, and I’m collecting it here in this variable,
action. Let’s print it out, give the game a little spin. This is just going to print back in whatever they say, but that’s okay for now.
I always like to run things in between.
Welcome to the role-playing game!
Do you want to (A)ttack, (H)eal, or (R)un away? I think that looks pretty nice. So, and then I’m going to say I want to attack, and then it returns the
a for attack.
Become a Member to join the conversation.