How To Target Specific Coins - JavaScript


#1

I’m currently stuck on bookkeeper and I can’t remember or find out how to target only gold coins!

I have tried item.type == “gold”;

But nothing happens


#2

Why are you trying to just collect gold? The directions say to, “collect coins until the clock reaches 30 seconds.” Coins add up to total gold, they just have varying values.


#3

@MunkeyShynes is right you need to just collect coins. Answering your specific question you can target only gold:

while (true) {
    var coin = hero.findNearestItem();
    if (coin  && (coin.bountyGold == 3) ) {
        hero.move(coin.pos);
    }
    if (hero.time > 30) {
        break;
    }
}

or replace coin.bountyGold with coin.value
BUT the hero doesn’t collect any other gold coin. The level passes only if the first coin is a gold one . I don’t understand why the hero freezes. Same behavior with moveXY. Another question: what is the difference between bountyGold and value?


#4

literally no difference (bountyGold might be a protected property while value isn’t tho)

u should do hero.findByType(“gold-coin”) to get an array of gold coins


#5

I tried this:

    var items = hero.findItems();
    if (items.lenght > 0){
        var goldCoins = hero.findByType('gold-coin', items);
        if (goldCoins.lenght > 0){
           var goldCoin = hero.findNearest(goldCoins);
           hero.move(goldCoin.pos);
        }
    }

and it doesn’t work…
/PS : I passed this level collecting all coins last year/


#6

of course it doesn’t work. You misspelled length. (idk about javascript but in Python u use len(goldCoins) instead of goldCoins.length)


#7

True it’s a mess in my head trying to learn python, java-script and coffee-script at the same time but this is really java-script :slight_smile:


#8

Thank you to everyone who replied. I actually learned a few things reading the responses.

I was for sure over thinking this level.

I woke up this morning reread the instructions and reset my code and completed it on the first try. :roll_eyes::roll_eyes::crazy_face:

Thanks again!