Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Improve Feedback Messages

00:00 You saw I got really confused about what these numbers are about, so let’s be a bit more descriptive. I’m going to print out here, let’s start with this one. I’m going to use an f-string: f"You attacked the monster for {damage} damage!"

00:21 And let’s add another call to print() here where I will say what the current health of the monster is. Let me see. Maybe this is actually nice to figure out what the health of both the monster and the player are right at the beginning of each game round.

00:37 So I’m going to add a print() call up here, another f-string: f"Your health: {player_health}, Monster health: {monster_health}".

00:57 Let’s make this a bit bigger, know what’s going on over here. Okay, I need to close these parentheses for the print() call. Now at the beginning of each turn, I’m going to get the information of what the health—maybe I’m even going to move that above as the first thing that happens for every game loop.

01:18 We start off at the beginning, and we’ll see how it changes after one move. That’ll make it easier to keep track of what’s happening. “You attacked the monster for blah, blah, blah damage.” Great. “You ran away.” That sounds good. And then I’ll add a similar call to print() down here:

01:37 f"The monster attacked you for {monster_damage} damage." That’s right.

01:50 And can update this a little too. f"You healed for {heal} health!"

02:00 This makes the text-based game a little more text-based, and hopefully it’s going make it easier for me to understand what’s actually going on and whether we do have any sort of bug in here or not. Let’s give it a go. F5.

02:15 Okay, so Your health: 100, Monster health: 150. Great. Do you want to (A)ttack, (H)eal, or (R)un away? I want to attack. All right, so I attack the monster for 14 damage.

02:28 The monster attacked you for 20 damage. My health is 80, the monster’s is 136, so that sounds good. So, attack again. Attacked the monster for 15.

02:36 The monster attacked for 16. And then I can see my health went down for 16 to 64. Monster’s health went down for 15 to 121. Okay, so this is looking good.

02:47 What happens if I heal? My previous health was 64. Now, no wait. Your health is 64. I healed for 30, but then the monster attacked me for 19, which means I essentially just healed for 11, and 64 plus 11 is 75. All right, so there’s no bug in here.

03:04 This is working as expected, and I can still run away. Perfect. And I got a bit more text-based output, and you can see it’s much easier to follow what’s actually happening in the game than it was before with the stub outputs that I had. Great.

03:19 We just made the text-based role-playing game a little text-based.

Become a Member to join the conversation.