Rich Forager Bug? - SOLVED!


#1

Hello, I am having trouble with Rich Forager. I am not sure if it`s a bug or not but it looks like one
Here is my code:

loop:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()

    if flag:
        self.pickUpFlag(flag)
        
    elif enemy:
             self.attack(enemy)
        
    elif item:
        item - item.pos
        item = itemPos.x
        item = itemPos.y
        self.moveXY(itemx, itemy)

#2

not sure what exactly your issue is but look at your elif item block. you have item = 3 different times in stead of
itempos =
itemx =
itemy =
that might help


#3

Ok, thanks I`ll try that. You know the Video they give so you can get help? I got that from their but it said “itemPos is not defined”. Here is my actual code http://codecombat.com/play/level/rich-forager


#4

it worked fine when I used your code from your first post with the changes. Not sure what you saw in the video but maybe try HD or full screen 'cause that code works just fine and it looks a litte different from what you posted.
Good Luck


#5

Ok thanks. I`ll keep trying.


#6

It looks like you have a minus sign instead of an equals sign when you are defining itemPos. Is that intentional?


#7

I changed it and it still said "itemPos is not defined"
Here’s my code:

loop:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()

    if flag:
        self.pickUpFlag(flag)
        
    elif enemy:
        self.attack(enemy)
        
    elif item:
        item = item.pos
        item = itemPos.x
        item = itemPos.y
        self.moveXY(itemX, itemY)

#8

Is it because of my browser? I found it better to use Chrome, Firebox kept crashing, and Internet Explorer was too slow.


#9

The problem is still here:

    elif item:
        item = item.pos
        item = itemPos.x             # 'itemPos' is not defined, and you redefine the same variable
        item = itemPos.y             # exactly the same problem here
        self.moveXY(itemX, itemY)    # 'itemX and 'itemY' are not defined

I guess you are trying to do this:

    elif item:
        itemPos = item.pos
        itemX = itemPos.x
        itemY = itemPos.y
        self.moveXY(itemX, itemY)

But why not make it simple?

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

#10

Ok thanks, I`ll try that


#11

@ant, on line 20 it says itemX and itemY is not defined. I know you have to fill it in, but see the purpose of:

self.moveXY(itemX, itemY)

Why is supposed to be there? I thought you direct your hero based on flags?


#12

I took the code from your first post, fixed the things already mentioned above, submitted it and it’s working fine.

I suggest to read through it once again – it’s about 10 lines of code, so it’s not that difficult…


#13

Well, if you can’t see an item, it is sure to be undefined.
Hope I helped!


#14

Ok thanks for the suggestions @ant @eab201903977


#15

I finally completed it!!!. I figured out that you have to define itemX and Y. So I fixed it and it worked.

Thanks for the help @ChronistGilver @ant @eab201903977 and @HeadMan. I really appreciate it. Thanks :smile: :smiley:


#16

Hey there! Here at CodeCombat we try not to give correct code. Would you mind rescinding your last post?
Thanks!


#17

Sorry guys :frowning: :cry: