Godot Version
online resource - Learn GDScript from Zero
Question
I’m currently on Lesson 14 (Multiplying) on the App/website “Learn to Code From Zero”. My question pertains to the 2nd practice problem.
It asks that if my character level is over 2, then the damage should be reduced by half.
this is the code provided to you, that you will add to:
var level = 3
var health = 100
var max_health = 100func take_damage(amount):
health -= amountif health < 0:
health = 0
The solution I have tried is as follows (I do not know how to do tabs in the forum posts, but it is formatted correctly in code. I have bolded my addition for easier reading):
var level = 3
var health = 100
var max_health = 100func take_damage(amount):
health -= amount**if level > 2:** **amount *= 0.5**
if health < 0:
health = 0
This is incorrect and is not reducing the damage taken. I have also tried the line “if level >= 3:” but this also did not work. I have tried both the >=3 and >2 if statements at the bottom of the code, but nothing changed. Looking over the lesson again did not help me find an answer.
What am I getting wrong? I don’t want to just ignore this and move ahead.