What is wrong with my code? (Multiplayer Treasure Grove-Python)

You never checked if there is an item to collect in the first place. Change the else: to elif item:.

I fixed it like you said, and it still says the same error message. Please help.

you define item as self.findItems(), which returns a list. Your character is trying to move to all the items at the same time, in a sense. You need to find the nearest

self.findNearest(self.findItems())

It still doesn’t work!
EDIT: I took out the bash.

Ill try it, thanks. :grinning:

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!
It didn’t work!!!

While using the command move, you should be targeting a dictionary of coordinates, like this:

self.move({"x":x, "y":y})

You are only targeting the numbers themselves.

OMG, THE TITLE SAYS MULTIPLAYER TREASURE GROVE PYTHON!!! Seriously, be more attentive.

Well, i think the error here is using finditems(). You should be using findnearestitem() and that would solve all.

This post is over a month old. Please keep the dead resting!

… Super Gamer What chronist said there is python. You are just using the compound boots, in that case get rid of

x=...
y=...

and just put

elif item:
    self.move(item.pos)

Did I not just say to keep the dead resting? SuperGamer has likely solved his issue by now, otherwise he would have continued posting.

It could be useful for someone else…

For example, for me. I didn’t realize that move could be used like that, nor that it behaves that way, until this post. (Even while the description is somewhat “clear”, sometimes you need to test it to understand)

1 Like

The problem with this, is that it moves 1 step each iteration, so it’s not useful in every situation. I think that movexy should be usable with “item.pos” as argument, or that we should have some move command that doesn’t require the coordinates to work. Like receiveing an object for reference as argument.

This is my code can someone help me

loop:

enemy = self.findNearest(self.findEnemies())
flag = self.findFlag()
item = self.findNearest(self.findItems()
if flag:
    self.pickUpFlag(flag)
elif enemy  == True:
    if distance < 30:
        if self.isReady("cleave") :
            self.cleave(enemy)
        else:
            if self.isReady("bash") :
                self.bash(enemy)
            else:
                if self.isReady("elecrocute") :
                    if self.canElectrocute(enemy) :
                        self.electrocute(enemy)
                else:
                    self.attack(enemy)
                    self.shield()
else: 
   self.moveXY(item.pos.x, item.pos.y)
  1. Do not use
elif enemy == True

instead:

if enemy:
  1. You have way too many nested ifs. Instead just use continue It tells the code interpreter to skip the rest of the code in the loop and start the loop again.
if flag:
     self.pickUpFlag(flag)
     continue
if enemy:
     if  distance < 30:
            if self.isReady("cleave"):
                   self.cleave(enemy)
                   continue
            if self.isReady("bash"):
                    self.bash(enemy)
                    continue

and so on

  1. Where are you giving a value to distance ?

  2. your code shields after each attack. In practice shield is extremely circumstantial.
    Do not shield unless something on that level require it.

thankyou but my hero isn’t collecting coins

If you have used continue after each other actions, then just add:

if item:
    self.moveXY(item.pos.x, item.pos.y)

at the end of the loop

apparently there is something wrong with

if flag:

but what is it