沙漠 地下商业,我写的代码无法搜集300个金币,帮忙看一下什么问题

def onSpawn(event):
# 派遣宠物绕地牢找寻:
coin = pet.findNearestByType(“gold-coin”)
if coin:
hero.say(“hello”)
pet.moveXY(coin.pos.x, coin.pos.y)
pet.fetch(coin)
# 别忘了把它返还给英雄:
pet.moveXY(hero.pos.x, hero.pos.y)
pass

pet.on(“spawn”, onSpawn)

while True:
# Guard peasants:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# 当你有300 +金币移动到红色标记:
if hero.gold >= 300:
hero.moveXY(50, 34)
pass

嗨,
而不是尝试在def onSpawn()中使用if语句,而是使用像pet.moveXY()这样的硬编码命令来让宠物收集硬币。 (if语句需要while-true循环)
我希望这有帮助。

coin = pet.findNearestByType(“gold-coin”) 这一关提示的代码,模拟宠物找不到 类型为gold-coin的金币,不知道怎么回事

我试图说什么,你应该使用pet.move XY(x,y)让你的宠物绕路径移动,而不是检查是否有一个硬币并取出它。 Mimic宠物不需要取钱币,只需将它们拉出来。
我希望这有帮助。
:lion: :lion: :lion:

1 Like