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

A fine mint Python

#20

I did it for you this time, but keep in mind in the future that improperly formatted Python code is hard to debug.

After formatting your code, I noticed that pickUpCoins isn’t indented. So it is never ran. Is this what you intended to do?

1 Like
#21

can you give me the lost vikking answer I dont understand it for like two weeks

#22

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

Write the attackEnemy function below.

Find the nearest enemy and attack them if they exist!

enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
while True:
hero.attack(enemy)
pickUpCoin()

Its not working can you help??

#23

help someone please give me their code

#24

help
with a fine mint

#25

What do you mean “their code”?
We don’t post solutions here. If you have a problem with a level you can describe your problem and we’ll try to help you.

#26

just give me the answer

#27

It’s not the best way to ask for help. I wrote before We don’t post solutions here. Please, describe your problem with this level. Also, it’s better to be polite if you don’t want to be banned (instead imperative phrases).

1 Like
#29
# Peons are trying to steal your coins!
# Write a function to squash them before they can take your coins.
def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
def attackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
while True:
    attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
    pickUpCoin()

i dont know whats wrong with the code but it wont work can someone help me?

#30

nevermind i just submitted and skipped and it worked

#31

[Please dont post solutions]

THIS CODE WORKING

#32
[Please don't post solutions]

that is the correct scripts

#33

Since you haven’t properly pasted your code here it’s impossible to tell if it’s structured properly.
See the FAQ for easy to follow instructions on how to do it properly. Basically, just use the </> button when copying from the game.

https://discourse.codecombat.com/faq

Assuming that your code is structured properly, there’s a few problems here. It’s probably not a good idea to name a function the same as a variable object (enemy). Also, the line with hero.distanceTo(enemy) does nothing and is not used. Also, you never call your attack function in your code. In your while True loop, all you need to do is call the attack function, you don’t need to define enemy again nor do you need another if enemy statement.

`

#34

i need help it will collect the coins but wont kill the peons

function pickUpCoin() {
var coin = hero.findNearestItem();
if(coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}

// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!
function attackEnemy ()
if (enemy) {
var enemy = hero.findNearestEnemy();
hero.attack(enemy);
}else{
while(true) {
pickUpCoin();
}

plz hlp

#35

I don’t see the attackEnemy() in your while(true) loop. Add that and you will run the hero will attack based on your function.

We won’t be able to see if there are any other formatting issues unless you format your code properly. Please check out the post below to learn how to do it.

#36

function pickUpCoin() {
var coin = hero.findNearestItem();
if(coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}

// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!
function attackEnemy ()
if (enemy) {
var enemy = hero.findNearestEnemy();
hero.attack(enemy);
}else{
while(true) {
hero.attack(enemy);
pickUpCoin();
}
}

#37

function pickUpCoin() {
var coin = hero.findNearestItem();
if(coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}

// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!
function attackEnemy ()
if (enemy) {
var enemy = hero.findNearestEnemy();
hero.attack(enemy);
}else{
while(true) {
hero.attack(enemy);
pickUpCoin();
}
}

now he cant move.

#38
#39
function pickUpCoin() {
    var coin = hero.findNearestItem();
    if(coin) {
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
}

// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!
function attackEnemy() {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }else{
   while(true) {
    if (enemy) {
        function attackEnemy()
    }else{
    pickUpCoin();
}
 
#40

There are three groups to this code:

  1. function pickUpCoin() // written for you
  2. function attackEnemy() // need to create
  3. while (true) loop just calling the two functions // uncomment the attackEnemy() to call it

Separate the while (true) from the attackEnemy() function . Since your attackEnemy() looks for any enemy, you don’t have to check for one before calling it. Oh, and to call a function just need the name like pickUpCoin(). Your function attackEnemy() is correct, the other details are just getting mixed up. I’d almost suggest restarting this level and just copy/paste your attackEnemy() function back in.