Rich Forager Help (python)


#1
loop: 
    flag = self.findFlag() 
    enemy = self.findNearestEnemy()
    item = self.findNearestItem() 
    elif enemy: self.cleave(enemy) 
    elif flag: self.pickUpFlag(flag) 
    elif enemy: self.cleave(enemy) 
    elif enemy: self.attack(enemy)
    elif item: 
        pos = item.pos 
        itemX = pos.x 
        itemY = pos.y 
        self.moveXY(itemX, itemY)

Can anyone help me? I can’t figure out how to finish this, my character just stops if I don’t kill everyone, I don’t know how to fix it!


#2

Well first, you define elif enemy 3 times. Is that necessary? Another thing, you start off with an elif statement. what are you saying else/if to? along with defining elif enemy 3 times, you have 2 with the same exact command. If you wanted to perform those statements for elif enemy, you could do something like this:

if enemy:
    if self.isReady("cleave"):
        self.cleave(enemy)
    else:
        self.attack(enemy)

#rest of your code here

something like that would prevent the 3 elif enemy statements. your other code, it seems like it would work. And if you wanted to, you could add a certain distance you would have to be for cleave. Cleave isn’t 100% necessary, but you should be able to use it.


#3

okay, so, i’ve tried this, and this is where I am getting an error: http://i.gyazo.com/5cc2eefff85f7bebe4c0339efe1892e2.png
I put it that way, I get that error
http://i.gyazo.com/ef85d7a73d4415f7ffe77b9b6559d794.png
that way, same error
http://i.gyazo.com/ced438c4aeaaa68dfe6a3e53c0a055b6.png
same one


#4

looks like a problem with your line indentation. you have to indent all your lines properly


#5

No, read the “fix your code”, because there’s 8 spaces on each indent.


#6

Bump, I still have no clue how to fix this


#7

We already told you one of the problems you chose to ignore it. (FYI those “fix your code” aren’t always accurate, most the time they are a bit obscure, as with most programming)

You have this code for starters…

if enemy:
if self.isReady("cleave"):

that right there is just wrong. don’t ask for help if you aren’t going to listen.

EVERY time you have an if the lines below it must be indented forward. (unless you complete the whole statement on the same line)

There’s even more glaring stuff wrong for instance.

elif flag: self.pickUpFlag(flag)
elif item:

wheres the initial if? you cant have a else if without a starting if.


#8

Fair warning, i’m not that experienced in python so no guarantee my example will work.

loop: 
    flag = self.findFlag() 
    enemy = self.findNearestEnemy()
    item = self.findNearestItem() 
    if enemy: 
        if self.isReady("cleave"):
            self.cleave(enemy)
        else:
            self.attack(enemy)
    elif flag:
        self.moveXY(flag.pos.x, flag.pos.y)
        self.pickUpFlag(flag) 
    elif item: 
        pos = item.pos 
        itemX = pos.x 
        itemY = pos.y 
        self.moveXY(itemX, itemY)

#9

Yes, i’ve figured it out now, I just changed everything to ifs and it worked. So now i’m on the last level!


#10

I’m so confused, I can’t win the level, my code is
loop:
flag = self.findFlag()
enemy = self.findNearestEnemy()
item = self.findNearestItem()
if enemy:
if self.isReady(“cleave”):
self.cleave(enemy)
else:
self.attack(enemy)
elif flag:
self.moveXY(flag.pos.x, flag.pos.y)
self.pickUpFlag(flag)
elif item:
pos = item.pos
itemX = pos.x
itemY = pos.y
self.moveXY(itemX, itemY)

Is it just that I need better armor? My character has 164 health. If it’s health is too low, then please tell me some armor that I should buy!


#11

I had 1700 gems and I was saving up for the 215.55 damaging sword thing. But in order to pass Rich Forager, I had to sacrifice somewhere like 730 - 790 gems :frowning:


#12

help plz (python)

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

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

#13

Indenting:

loop:
    flag = ...
    # etc

    if flag:        
        self.pickUpFlag(flag)
    elif ...
        #etc

#14

I need help on this topic too


#15

I did every thing right it would work but the only problem is indentions


#16
loop: 
    flag = self.findFlag() 
    enemy = self.findNearestEnemy()
    item = self.findNearestItem() 
    if enemy:
        if self.isReady("cleave"):
            hero.cleave(enemy)   
    else:
        self.attack(enemy)
     elif item: 
        pos = item.pos 
        itemX = pos.x 
        itemY = pos.y 
        self.moveXY(itemX, itemY)

#17

I don’t see how this has incorrect indentions


#18

any help will be highly appreciated


#19

I really don’t think you didn’t realize this in a year, but the error is in the last few lines. You can’t put an “elif” statement as a reply to an “else” statement, as by the time you reach the “else,” there are no other possibilities for the “elif” statement to address. Perhaps you’ve gotten the “else” and “elif” statements switched?


#20

Actually, you also need to attack the enemy IN the if enemy statement. Instead of attacking the enemy when there is an enemy, you attack the enemy when there ISN’T an enemy, hence the freezing of your hero when any enemies appear.