I have basically no idea where to start.
def removeByType(enemies, excludedType):
tempList = []
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.id == "sand-yak":
pass
return tempList
while True:
enemies = hero.findEnemies()
enemies = removeByType(enemies, "sand-yak")
enemy = hero.findNearest(enemies)
if enemy:
hero.attack(enemy)
All I have done is add
if enemy.id == "sand-yak":
and
enemies = hero.findEnemies()
And I think those r wrong.
Aya
December 14, 2021, 7:34pm
3
In this level, you are checking types, and you already have the type that you are excluding in the second parameter, so you need to make it this way:
if the type of enemy does not equal excludedType:
append the enemy to the tempList
As for this, it isn’t necessary, enemies is already defined in the line below.
def removeByType(enemies, excludedType):
tempList = []
for enemy in enemies:
if enemy.type != excludedType:
hero.say("leave that yak alone!")
+=1
pass
return tempList
while True:
enemies = hero.findEnemies()
enemies = removeByType(enemies, "sand-yak")
enemy = hero.findNearest(enemies)
if enemy:
hero.attack(enemy)
It says indentation error on the +=1
And I feel like it takes more than a simple +=1 to append.
abc
December 14, 2021, 9:56pm
7
I recommend that you just find the nearest enemy, and if that enemy’s type is not equal to “sand-yak”, then attack the enemy. Rangers work best to attack from afar, this way you won’t have to move if you have a decent ranged weapon.
I don’t know rangers. I stick with warriors
abc
December 14, 2021, 11:28pm
9
It would work even if you use warriors.
I will try it. But later.
I tried again, ad this is my updated code.
def removeByType(enemies, excludedType):
tempList = [0]
for enemy in enemies:
if enemy.type != excludedType:
hero.say("leave that yak alone!")
tempList +=1
pass
return tempList
while True:
enemies = hero.findEnemies()
enemies = removeByType(enemies, "sand-yak")
enemy = hero.findNearest(enemies)
if enemy:
hero.attack(enemy)
I thought might of figured out what to append and how, but I apparently was wrong.
Aya
January 7, 2022, 6:41am
12
hellodaddy:
tempList = [0]
So this should be an empty array, no need to add the zero, brackets are enough.
hellodaddy:
tempList +=1
To clear things out, the append works this way:
myList.append(myItem)
And i think that this is quite confusing, maybe you should name each one of them a different name.
For example:
enemies = hero.findEnemies()
notYaks = removeByType(enemies, "sand-yak")
THanks for those pointers, I think that mostly fixed the problem, and the append thing I shouldve seen, but anyways, It still attacks the yak, and I am not utilizing the notYak thing, and I think that that is the prob. ANy tips?
def removeByType(enemies, excludedType):
tempList = []
for enemy in enemies:
if enemy.type != excludedType:
hero.say("leave that yak alone!")
tempList.append("sand-yak")
pass
return tempList
while True:
enemies = hero.findEnemies()
notYak = removeByType(enemies, "sand-yak")
enemy = hero.findNearest(enemies)
if enemy:
hero.attack(enemy)
Aya
January 8, 2022, 3:57pm
14
Yeah, we should fix that.
So this is unnecessary
and instead of enemy, replace both of them with notYak, but make sure to put that in a for-loop as notYak is a list
for myItem in myList:
if myItem:
hero.move(myItem.pos)