Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

請教 不知道哪裏錯了?就是不運行


not move:rofl:


not move

hit backspace once before the else:
actually, lemme just type up the level and paste in your code and edit it.
This is way to frustrating

1 Like

ok i got it fixed. I’ll message you the solution, since this is an easy level, and you have shown your efforts. @Chaboi_3000 am i allowed to share the solution?

1 Like

No(must 20 characters)

1 Like

I can not think of any other way to finish this level.

@Chaboi_3000 we’re literally telling him what changes to make in his code so he can pass the level though… what’s the difference?

你的缩进是对的。
然而你在打食人魔这里错了。
while循环代替for循环时,由于for循环是遍历所有的对象的(无论对不对这个对象做什么事情),所以,while循环里的index属性也得遍历所有的对象 就像这样:
while(index < length):
somestatements
index+=1 (这里是让Index自增而遍历所有对象)
所以 通关代码应该是这样:
while True:
(定义enemies与enemyIndex)
while enemyIndex < len(enemies):
(定义enemy并攻击)
enemyIndex+=1
pass
(移动回中央)

附:缩进你自己来吧(我来凑成20个字我来凑成20个字)

Step by step really teaches while giving the code out will be the same as cheating.

fine… but we gotta teach him why to do this or that though… and we didn’t… and life’s hard :frowning:

Can you post your code here so I can copy and paste in and see whats wrong? There I can help. :slightly_smiling_face:

while True:
enemies = hero.findEnemies()
enemyIndex = 0
# 将攻击逻辑放到 while 循环里来攻击所有的敌人。
# Find the array’s length with: len(enemies)
if enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# “!=” 意思是 "不等于"
if enemy.type != “sand-yak”:
# 当敌人的健康值大于0,攻击它!
if enemy.health > 0:
hero.attack(enemy)
else:
hero.moveXY(42,32)
pass

    # 在两波敌人之间,移动回中央。

I accept"step by step".but how to "step by step"
So far ,I still don’t understand why hero doesn’t move?

怎樣定義enemy?
我好像衹做了攻擊了

Can you format your code according to the FAQ?

discourse.codecombat.com/faq

my english is not too good.so i no to test it.:sweat_smile:

有两种办法 一种是直接用hero.findNearestEnemy()方法 另外一种是用hero.findNearest(hero.findEnemies()) 没记错的话 第二种是老版本使用的

牧羊人这关我也卡了很久,也是一样的原因
呃,试试把if enemy.health>0换成while循环
然后问题就是。。。你的index干啥去了?你打完一个怪要把那个index+=1啊。。。:sweat:

你们都没发现他的index一直是0吗。。。有毒 :joy: