Hello, I have been struggling with this level. This is the code that I have so far and the error code says "expected an identifier and isntead say ‘)’ – in this line hero.buildXY(“fence”, hero.pos.x, yak.pos.y + 10); }
while(true) {
var yak = hero.findNearestEnemy();
if (yak) {
if (yak.pos.y > hero.pos.y); {
hero.buildXY("fence", hero.pos.x, yak.pos.y - 10); } }
if {
hero.buildXY("fence", hero.pos.x, yak.pos.y + 10); }
else {
hero.moveXY(hero.pos.x + 10, hero.pos.y); }
}
First, you have no if conditional regarding what happens if yak position y coordinate is less than hero position y coordinate.
Second, although in this instance it does work to use hero.pos.x together with yak.pos.y, you have to be careful of such a mixture. This works better with using just yak.pos.x and yak.pos.y together.
Welcome javier_denis!
Have a look at this line of yours and then take a look at the other “if” lines.
When using it, it always needs a condition, which it didn’t get in this line!
thanks to you two i managed to make the player move and place the first fence, but he wont place the second one so he gets pushed by the second yak. this is what i got so far
while(true) {
var yak = hero.findNearestEnemy();
if (yak) {
if (yak.pos.y > hero.pos.y) {
hero.buildXY("fence", hero.pos.x, yak.pos.y - 10); } }
if (false){
hero.buildXY("fence", hero.pos.x, yak.pos.y + 10); }
else {
hero.moveXY(hero.pos.x + 10, hero.pos.y); }
}
Fair enough, but if I were you I’d make sure I could complete the level as it’s supposed to be completed as well. It shouldn’t require trial and error.
Look at these two lines:
if (false) { # is not a statement.
What else could you use?
You’re almost there! Don’t give up.
-Danny
I know this is a dead topic, but in case you still need help javier_denis, did you match up all of your if statments with brackets? I forgot one bracket when I was on this level, too.