# Reaping Fire Help (Python)

Hi guy recently i’ve been trying to solve the Reaping Fire level and have run into these weird glitches saying that for-else statements are unsupported, costOf is a protected property, and summon is a protected property. My hero collects gold just fine but when it reaches 20 gold he just stops moving.

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.

def chooseStrategy():
enemies = hero.findEnemies()
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold >= hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
for enemy in enemies:
if enemy.type == "fangrider" and enemy.x < 37:
return "fight-back"
# Otherwise, return "collect-coins"
return "collect-coins"

def commandAttack():
# Command your griffin riders to attack ogres.
hero.summon("soldier")
friends = hero.findFriends()
for friend in friends:
enemy = hero.findFriendlyMissiles().findNearestEnemy()
hero.command(friend, "attack", enemy)
pass

def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
pass

def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.pos.x < 36:
hero.attack(enemy)
pass

while True:
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
commandAttack()
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()

Hey @iggymaster99! Thanks for posting your code + screenshots of equipment and the errors.

When I tried to run your code, I got this error on line 20:

Could you explain the code on that line please? I don’t understand why you’ve used hero.findFriendlyMissiles().findNearestEnemy()

Oh crud. I think I was messing around with the code and autocomplete did that. I took that out but now the griffin riders just stand there until I summon a second one.

# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.

def chooseStrategy():
enemies = hero.findEnemies()
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold >= hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
for enemy in enemies:
if enemy.type == "fangrider" and enemy.x < 37:
return "fight-back"
# Otherwise, return "collect-coins"
return "collect-coins"

def commandAttack():
# Command your griffin riders to attack ogres.
hero.summon("griffin-rider")
friends = hero.findFriends()
for friend in friends:
enemy = hero.findNearestEnemy()
hero.command(friend, "attack", enemy)
pass

def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
pass

def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.pos.x < 36:
hero.attack(enemy)
pass

while True:
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
commandAttack()
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()

You have few mistakes:

• Summoning Units in commandAttack: The function commandAttack is summoning a “soldier” instead of a “griffin-rider”. The goal is to summon a “griffin-rider” if there is enough gold.

• Finding Nearest Enemy for Griffin Riders: The function commandAttack is trying to use hero.findFriendlyMissiles().findNearestEnemy(), which is incorrect. Instead, it should use friend.findNearestEnemy for each griffin-rider.

• Condition in chooseStrategy: Ensure that hero.gold >= hero.costOf("griffin-rider") checks the exact cost and does not miss the opportunity to summon griffin-riders.

• Missing else Clauses: The code does not use elif or else in the strategy decision-making, which can lead to incorrect actions being taken in one iteration of the loop.

• Wrong Syntax: enemy.x should be enemy.pos.x

^ by ChatGPT

1 Like

Also in Python, when comparing strings you should use
equalsTo() or is when doing so, like:

if strategy is "griffin-rider":
commandAttack()

somehow CoCo doesn’t give an error on that. But just a friendly reminder

1 Like

Okay. I think that the level has some problems. It says summon is a protected property and I’m stuck.