Luke10
November 15, 2015, 5:06pm
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)
HeadMan
November 15, 2015, 5:17pm
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
Luke10
November 15, 2015, 5:32pm
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
HeadMan
November 15, 2015, 6:09pm
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
Luke10
November 15, 2015, 6:15pm
5
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?
Luke10
November 18, 2015, 9:35pm
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)
Luke10
November 18, 2015, 9:39pm
8
Is it because of my browser? I found it better to use Chrome, Firebox kept crashing, and Internet Explorer was too slow.
ant
November 18, 2015, 10:33pm
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)
Luke10
November 19, 2015, 4:08pm
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?
ant
November 19, 2015, 8:33pm
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…
Well, if you can’t see an item, it is sure to be undefined.
Hope I helped!
Luke10
November 19, 2015, 11:58pm
14
Ok thanks for the suggestions @ant @eab201903977
Luke10
November 24, 2015, 4:03pm
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
Hey there! Here at CodeCombat we try not to give correct code. Would you mind rescinding your last post?
Thanks!