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


#1


#2

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


#3

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


#4

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())

#5

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


#7

Ill try it, thanks. :grinning:


#8

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


#9

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.


#11

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


#12

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


#13

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


#14

… 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)

#15

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


#16

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)


#17

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.


#18

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)

#19
  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.


#20

thankyou but my hero isn’t collecting coins


#21

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


#22

apparently there is something wrong with

if flag:

but what is it