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");
}
}
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...
|| 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.
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.