My code on the level “Clash of Clones” bugs out on the cleave command.
My code:
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.type == ‘self’:
while enemy.health > 0:
if self.isReady(“cleave”):
self.cleave(enemy)
else:
self.attack(enemy)
if enemy.type ! “Sand-Yak”:
while enemy.health > 0:
if self.isReady(“cleave”):
self.cleave(enemy)
else:
self.attack(enemy)
enemyIndex = enemyIndex + 1
The error code reads:
Fix your code:
Attempted to asgin readonly property
This line is the one that is highlighted red: self.cleave(enemy)
Are by any chance trying to cleave yourself?
if enemy.type == 'self':
while enemy.health > 0:
if self.isReady("cleave"):
self.cleave(enemy)
The game engine probably sees it as a sneaky attempt to modify your self.health
value
No I’m trying to target the clone whose type is “self”.
The clone’s type is not self
. It’s whatever type your hero is.
which you could define as “self.type”
Also cleave doesn’t explicitly require a target due to it’s AOE nature, I just make sure I’m in range of something I want dead (or several somethings) and then self.cleave(); as the range to my target is more important. (Unless cleave has been updated since I played a year ago to chase targets as attack does.)
Does ! work the same as !=? shrug neat.
Please put your code block inside of the appropriate function ([ code ] [ /code ]) as it will be easier to read your indentation.
Also, not necessary on this level but it’s generally considered best to check if the variable enemy has a value before running commands that target said variable