# Survive the waves of ogres.
# If you win, the level gets harder, and gives more rewards.
# If you lose, you must wait a day to re-submit.
# Each time you submit gives a new random seed.
while True:
enemy = hero.findNearestEnemy()
if hero.isReady("cleave"):
hero.cleave(enemy)
else:
hero.attack(enemy)
The error says "attack’s argument expected object but got null
‘if enemy’ does that for you. You are testing to see if the object ‘enemy’ is null (false) or True (it has a value). Tho not in this case, there might be instances where you want to test for ‘no enemy’. Something like this, for example:
if item and not enemy:
getItem(item)
elif enemy:
hero.attack(enemy)
Ah okay thanks. When I have a chance to get back to my pc I’ll have another go.
I just started learning to program. I have a book called python crash course and found this game by luck. I even learned things here I’ve yet to cover in the book. Like while loops and if statements
True, but in this case, everything is within the ‘while true’ loop, so ‘enemy’ gets refreshed every iteration…dead enemies will not be included in the array.
Anyway, that is still a good suggestion to keep in mind.
Sorry I have given it a go here but it isn’t working as expected stil
# Survive the waves of ogres.
# If you win, the level gets harder, and gives more rewards.
# If you lose, you must wait a day to re-submit.
# Each time you submit gives a new random seed.
while True:
enemy = hero.findNearestEnemy()
if enemy:
if hero.isReady("cleave"):
hero.cleave(enemy)
else:
hero.attack(enemy)
else:
hero.say("Clear")
The above code, indented correctly, works. He would attack the first enemy then after that just stand there and let them kll him. Poor guy I can relate
It is the first level of the brawl. Sadly I accidentally submitted the broken version and now have to wait a day