I don’t know what to do next.
while True:
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
# If you have enough gold, summon a soldier.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
# Collect gold.
# Use a for-loop to command each soldier.
# For loops have two parts: "for X in Y"
# Y is the array to loop over.
# The loop will run once for each item in Y, with X set to the current item.
for friend in hero.findFriends():
if friend.type == "soldier":
enemy = friend.findNearestEnemy()
# If there's an enemy, command her to attack.
# Otherwise, move her to the right side of the map.
Hmm where is this level at? (probably mountain)
~ Orb
1 Like
And I just reseted my progress to do C++ (I still can do Python), please give me a screenshot of your code, the scene, and the goals together
~ Orb
1 Like
Yes. a little ways into the mountain.
1 Like
Okay hold on a sec.(200000000000char)
1 Like
Whole screen, or just a screenshot of the code?
1 Like
Whole screen, also tell me what the level’s goals are
~ Orb
1 Like
the goals are defeat the ogres and protect the peasants.
1 Like
Oh ok I remember this now.
So far your code is correct apart from one mistakes, but otherwise you just need to add stuff according to the comments.
The mistake:
for friend in hero.findFriends():
hero.findFriends()
find ALL your friends. Is there a way to only find soldier-type friends?
# If there's an enemy, command her to attack.
- You can see what tool to use in the comment (hint: look at the first word)
- In that tool, you need to
hero.command(soldier, "attack", enemy)
to attack the enemy
# Otherwise, move her to the right side of the map.
- Look at the first word again, this tool is a sub-tool of the tool above.
- Find a point close to that opening in the mountain there, and
hero.command(soldier, "move", {"x": thatXPos, "y": thatYPos}) Here's all the tips! ~ Orb P. S. In the next level, it is exactly the same, but you can't let your troops die or a headhunter will spawn.
# If your troop’s health < troop’s max health / 2 (or 3), send her back to you```. This is a clue of what you should do.
1 Like
Can you send me the link?
Lydia
1 Like
The link to what?(20000000chars)
1 Like
I don’t really know how to send a link for the level. I know where to put it in the forum, but i don’t know how to get it. I have to be done with coding today though.
1 Like
Just click the website domain link (the .com thing), and then it will pop out a longer link. Copy it all and paste it here
~ Orb
2 Likes
Maybe you have to write:
if enemy:
hero.command(friend, "attack", enemy)
3 Likes
So next, you just have to command your friends (AKA soldiers) to attack enemy IF there is one. And to move to one point to defend IF there is NOT an enemy.
Hope that helps, Lydia
how do you command them to move without a target?