Can i somehow summon someone who can help me collect gold? also I still haven’t beat it yet
You can summon peasants, but you don’t need that
You should remove this line and it should work fine
It didn’t work. How could it not work?
what is your code? maybe it will work for me
Hi @derek_brown1,
We don’t post/share solutions on this forum. We’re here to help you, and to help you improve, which won’t happen if we just give you the answer.
So, @AnSeDra has been right so far in what he’s said. Please post you current code. It’s a good idea to do that every time you follow a bit of advice and change your code. It allows us to see that you’ve done the right thing.
Also what AnseDra means here:
Is that you should add ‘indentation’. Which is the spaces at the start of each line following a while true, if, elif or else statement. It helps us read your code, and indentation can be the source of an error, so it’s very important that you use it. (And it means we don’t have to do it manually, which takes a long time, when you can just copy it in directly from CodeCombat.)
Thanks
Danny
But i am not sure how to do it!
can you show me what it looks like?
It looks like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# See the spaces?
All you need to do is put two lines down with three ``` on each. Then, make an empty line in between them. Then go to the codecombat level, select all of your code, copy it, then paste it in between the two lines of backticks.
working on it now 123
finished code. At the top of the page
You’re missing an m here:
You still haven’t removed the while loop from the pickUpCoin function.
Neither have you changed this:
Try this for that bit:
still not working . Can you check my code in the level and see what else I need to change?
Could you send the code that you have right now?
Never MIND I FIGUREd IT OUT!
Congratulations! You should tick a message as solution to let others know that you don’t need help anymore on this level.
Thank you, @Deadpool198.
i need help with my code, my griffin-riders are not responding to the command and also my code maybe has other problems.
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"
enemy = hero.findNearestEnemy()
if enemy and enemy.type == "fangrider":
return "fight-back"
# Otherwise, return "collect-coins"
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
friend = hero.findFriends()
friends = hero.findFriends()
if friend in friends:
hero.command(friend, "attack", enemy)
for enemy in enemies:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
if enemy and enemy.pos > hero.pos:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
hero.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
This isn’t quite how you do a for loop.
You don’t need to define friend, only friends.
When you write this line:
for friend in friends. It automatically defines it.
Also don’t for loop through the enemies inside the other for loop. Instead define enemy as the friends nearest enemy.
You can’t compare .pos like that. You have to get the .pos.x bit.
Danny