Hey there,
I have a Problem that my Code never finishes.
Here is my Code:
var gems = hero.findItems();
var xPlusTenX = 20;
var xPlusTenGem = 25;
var nextGem = 0;
while(true) {
while (hero.pos.x < xPlusTenX && hero.pos.y < 35) {
hero.move({'x': xPlusTenX, 'y': 35});
if(hero.pos.x === xPlusTenX && hero.pos.y === 35){
break;
}
}
while (hero.pos.x <= xPlusTenGem && hero.pos.y >= 25) {
var gemsIndex = gems[nextGem];
//hero.say(gemsIndex);
if(gemIndex){
hero.move(gemsIndex.pos);
if(hero.pos.x === xPlusTenGem){
xPlusTenX = xPlusTenX + 10;
xPlusTenGem = xPlusTenGem + 10;
nextGem++;
break;
}
}
}
}
I know what the Problem is but I’m lacking in finding a solution.
Im finished the Level, but the Problem is that after picking up the last Gem, the hero tries to find the next one.
Though there are no more Gems he hangs up in a loop.
I tried it with an if tho find out if nextGem === 3 but then he stoped at the first base right when he walks.
I would be happy about all tips for a solution.