Treasure Grove (JAVA)

Greeting All !
As I understand there’s 2 legit ways to beat SUBJ level:

  • use flag, and manually pick up gold coins;
  • kill AI, and grab all coins, but he’s is peaceful, so there’s no point of killing him.

I wanna try simplify my code, by telling my char to pick up only gold and silver coins;
Unfortunately, I did about 120 levels in forest, and there was not even one sign on this item.value definition, I think my char is not reacting to it. AI is always getting them first.

is it even possible?

while (true) {
    var item = hero.findNearestItem();
    if (item) {
        item.value == 2 || 3;
        hero.moveXY(item.pos.x, item.pos.y);
    }
    else {
        item.value == 1;
        hero.say("Bruh keep the change");
}
}

Thanks for all replies

You should also use item.type


(item.value == 2 || 3 && item.type == "coin");

like this?

1 Like

Don’t add the ; in an if statement but you are correct.

2 Likes

The code in your first post:

  • This is an empty statement (it serves no purpose for your program). Try putting this code into an if statement.

  • item.value == 2 || 3 is not doing what you think it does…

// this checks if (item.value is 2) OR (if 3 is a real value)
// and it will always evaluate to true
//     see why at https://www.w3schools.com/js/js_booleans.asp
//     in the section "Everything With a 'Real' Value is True"
if (item.value == 2 || 3) { }

// the correct way to check if item.value is 2 or 3
if (item.value == 2 || item.value == 3) { }

// or you could just do a 'greater than or equal to' check...
2 Likes

This.

|| means or and it is a Boolean operator. It means that both sides by them selves get converted to either true or false. The 3 by itself is interpreted as true, then the whole if argumentwill always be true no matter what is on the other side.

1 Like

stuck on this level, was trying to kill AI, but it kept re-spawning
still trying to solve it with “identifying coin value”

`
My logic:

if coin value equals to 2 or 3 I’m picking them up
else is coin is not 1 I should pick them up too
sounds good, doesn’t work

while (true) {

    var item = hero.findNearestItem();

    if (item.value == 2 || item.value == 3) {
        hero.moveXY(item.pos.x, item.pos.y);

    } else {
        if (item.value != 1)
            hero.moveXY(item.pos.x, item.pos.y);
    }
}

just beat the level with a “flag”, but I want my CHAR to do it automatic with a coin.value code, plz help

This is an optional multiplayer level anyways. If you can’t come up with anything clever to beat your enemies, leave the level and come back to it later. You’ll learn a few tricks from other levels.

1 Like

every time I pass the level, I say to my self “you just got lucky, you don’t know what you doing” but I pass every time xD