Hi, could someone help with the coding about type

Hi there, I’m in the desert level “the trails”, course python
about collecting mushroom.

I feel a bit confused by the item.type, it seems the clause: if coin.type == “Mushroom” won’t work.
like in the following code, the character will not go search for the mushroom (it works when the if judgement is removed)

The code
    while flagViolet:
        xViolet = flagViolet.pos.x
        yViolet = flagViolet.pos.y
        self.move({"x":xViolet, "y":yViolet})
        if self.pos.x == xViolet and self.pos.y == yViolet:  
            self.pickUpFlag(flagViolet)
            
        coins = self.findItems()
        coinIndex = 0
        while coinIndex < len(coins):
            coin = coins[coinIndex]
            if coin.type == "mushroom":
                x= coin.pos.x
                y= coin.pos.y
                self.moveXY(x, y)
                coinIndex += 1
            else:
                coinIndex += 1

what is the problem of the if coin.type == "mushroom":clause?

I think the mushrooms don’t have a type. Just use self.findNearest(self.findItems())

or change coin to item

That would not make any difference. It is still defined as a certain item in the list of self.findItems(). Whether it is a coin or not is irrelevant.

yea. I was thinking about distinct the items, say there’re coins, poison mushroom and the normal mushroom. That’s when we’ll need a judgement. I think this is a nice game, but all in all it’s a nice game, which I really appreciate but still due to it’s laking of debugging tools or a formal manual. We learner have no way to know whether a “can’t be implemented part” is restricted by the design or due to the wrong coding. That maybe the only part (except that part I really enjoy the game) that annoys me and where I realize it is no more than a game. Anyway I choose to back to python and algorithm textbook now.

Thank you anyway.

:cupid::broken_heart: