Multiplayer Treasure Cove (HELP)


#1

Hello! I have been trying to pass this level for a while and whenever I run my hero moves and attacks but then stops. I was wondering if you guys could help out! :blush:

Heres my code:


#2

You define item but do nothing with the variable. You have no code to move to or collect any item. You don’t need to define an array of items. Just collect each item using your defined variable. Also, you don’t check to see if there’s an enemy so your while True loop only iterates once for the attack code. Check for the enemy first and then it will continue the attacks as long as the enemy exists.


#3

Use if.

if enemy:
    hero.attack(enemy)

#4

It’s still not working for me, i’m not really sure what i’m doing wrong.

Here’s my code:

while True:
var = hero.findNearestItem()
var = hero.findItems()
if enemy:
enemy = hero.findNearestEnemy()
hero.attack(enemy)


#5

It looks like you have combined javascript type variable definitions with python. Using the code you posted earlier in the screenshot, all you had to do was read my previous post and the post after it by I_can_rob_you. Everything you needed to do to fix your code was in there.


#6

I did the code but it still isn’t working it’s not letting me move.


#7

so post your updated code with the changes you’ve made and we’ll see what needs to be done from there.


#8

It’s the same code I posted after I_can_rob_you, but the code shows nothing wrong but i’m not moving.

Here’s my code:

while True:
var = hero.findNearestItem()
var = hero.findItems()
if enemy:
enemy = hero.findNearestEnemy()
hero.attack(enemy)


#9

First of all, it looks like you are messing Python with J.S and also, hero.findItems() find all items but in order to find one nearest coin/item, you have to change that to hero.findNearestItem() and change the variable names to 2 unique ones. If you want to find an item and pick it up, simply tell your hero to check if there is an item, and make it move to the X and Y coordinates, or use the hero.move() command(if you have the correct boots).


#10

It looks like you are lacking the understanding of some very basic concepts to be as far along as you are and struggling with the simple code of this level. I would recommend resetting and starting over. It only gets more difficult from here. Sarven Desert is much harder and Cloudrip Mountain is much harder than that. If you lack the foundation necessary to complete levels in Backwoods Forrest you are going to be in real trouble in the next campaign.


#11

Okay, I’m only eleven so it’s really hard for me to understand a lot of this.:sweat_smile:


#12

You need to add an if because there is not always going to be an enemy.


#13

@Naima_Fausto You probably need to do:

while True:
    enemy = hero.findNearestEnemy
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    if enemy:
        hero.attack(enemy)

#14

If you want to add an extension, you could put an else in there.