Level: Shine Getter - Python


#1

I am not sure what I need to do to make this work. I am not asking for the solution, but rather a hint to get it working.
Thanks!

Edit - I fixed my code to where it will not pick up all coin if I change if coin.value == 3: to if coin.value > 0:

loop:
coin = self.findItems()
coinIndex = 0 
while coinIndex < len(coin):
    coin = coin[coinIndex]
    if coin.value == 3:
        pos = coin.pos
        x = pos.x
        y = pos.y
        self.moveXY(x, y)
coinIndex += 1

#2

Fixed it. I got my ‘coin’ and ‘coins’ confused I believe.

http://pastebin.com/Den4tVTi


#3

yeah, that and the paste bin code is indented correctly.


#4

Yeah. I am not sure if my copy and paste didn’t move over correctly? I think it was fine in-game. I could be wrong. I made a lot of changes.


#5

Did you use three back ticks at the head and foot of the code (see the FAQ)? I just learned about this and it fixes all the copy and paste formatting errors.


#6

Guys. My code doesn’t work. Can u tell me what i did wrong?
loop: {
var coins = this.findItems();
var coinIndex = 0;

// Wrap this into a loop that iterates over all coins.
while (coinIndex < coins.length) {
    var coin = coins[coinIndex];
    // Gold coins are worth 3.
    if (coin.value == 3) {
        // Only pick up gold coins.
        this.moveXY(coin.pos.x, coin.pos.y);
    }
    coinIndex += 1;
}

}


#7

@Captain_Tater Remove the colon from loop: { — it should be loop {
Or you can also use the equivalent standard form: while (true) {


#8

I did what you told me, and its still red.


#9

while True:
coins = hero.findItems()
coinIndex = 0

# Wrap this into a loop that iterates over all coins.
while True:
    
    coin = coins[coinIndex]
# Gold coins are worth 3.
if coin.value == 3:
    # Only pick up gold coins.
    hero.moveXY(coin.pos.x, coin.pos.y)
    coinIndex += 1
    pass

this is my code what am i doing wrong?


#10
     thanks for the help.but  why can't use while true: