can you give me the lost vikking answer I dont understand it for like two weeks
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??
help someone please give me their code
help
with a fine mint
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.
just give me the answer
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).
# 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?
nevermind i just submitted and skipped and it worked
[Please dont post solutions]
THIS CODE WORKING
[Please don't post solutions]
that is the correct scripts
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.
`
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
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.
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();
}
}
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.
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();
}
There are three groups to this code:
- function pickUpCoin() // written for you
- function attackEnemy() // need to create
- 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.
who can help me this is my code:
def pickUpCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
# Schrijf hieronder de attackEnemy functie.
# Vind de dichtsbijzijnde vijand en val deze aan als deze bestaat!
def makeAFart():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
while True:
makeAFart();
pickUpCoin()