Hi, sorry for making another topic, (I’ve been making a lot recently), but I can’t figure out what’s going on with my code and why it’s not working, can someone help please?
return #Commented out to stop infinite loop.
return #Commented out to stop infinite loop.
# Use while loops to pick out the ogre
while True:
enemies = hero.findEnemies()
enemyIndex = 0
# Wrap this logic in a while loop to attack all enemies.
# Find the array's length with: len(enemies)
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!
while enemy > 0:
hero.attack(enemy)
pass
# Between waves, move back to the center.
hero.moveXY(40, 32)
@Chaboi_3000?
Probably because your code is commented? Try removing the return
statements.
1 Like
But then it won’t load again! AHHHHH!
You forgot to add to the enemy index, so it’s stuck forever going through the array.
1 Like
Here’s my code and I’m still standing still.
#Commented out to stop infinite loop.
#Commented out to stop infinite loop.
#Commented out to stop infinite loop.
#Commented out to stop infinite loop.
# Use while loops to pick out the ogre
while True:
enemies = hero.findEnemies()
enemyIndex = 0
# Wrap this logic in a while loop to attack all enemies.
# Find the array's length with: len(enemies)
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!
while enemy > 0:
hero.attack(enemy)
enemyIndex += 1
pass
# Between waves, move back to the center.
hero.moveXY(40, 32)
I’m not moving and I’m not fighting.
This is a little advanced, but try a for loop instead.
while True:
enemies = hero.findEnemies()
targets = []
for enemy in enemies:
if enemy.type <> 'sand-yak'
targets.append(enemy)
#do something
Hope this helps!
Append for loops aren’t that hard lol
-Grant
I think you shouldnt do for loops yet if your not there yet.
1 Like
Hey I’m just trying to help ok?
2 Likes
@CocoCharlie helped me off of the discourse, but thanks.
1 Like