Rich Forager Bug? - SOLVED!

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)

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

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

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

Ok thanks. I`ll keep trying.

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

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)

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

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)

Ok thanks, I`ll try that

@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?

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…

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

Ok thanks for the suggestions @ant @eab201903977

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:

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

Sorry guys :frowning: :cry:

1 Like