I require assistance (javascript)


#1

// You can put one if-statement within another if-statement.
// Be careful how the if statements interact with each other.
// It’s helpful to start with one outer if/else,
// using comments as placeholders for the inner if/else:

while(true) {
var enemy = hero.findNearestEnemy();
// If there is an enemy, then…
if(enemy) {
// Create a distance variable with distanceTo.
var dte = hero.distanceTo(enemy);
// If the distance is less than 5 meters, then attack.
if (dte < 5)
hero.attack(enemy);
// Else (the enemy is far away), then shield.
} else {
(dte > 5)
hero.shield;
// Else (there is no enemy)…
} else { //THIS IS WHERE THE ERROR IS
// … then move back to the X.
hero.moveXY(40, 34);
}
}

Alright so problem is I keep getting "expected an identifier and instead saw ‘else’ "
My next problem is this level “Stillness in motion” requires // Else (the enemy is far away), then shield. now the problem with this is it is a rogue level and I can not use a shield as rogue… ?


#2

I just changed this to hero.shield(); and still no luck, is it because I don’t have shield as an ability I can use?


#3

// You can put one if-statement within another if-statement.
// Be careful how the if statements interact with each other.
// It’s helpful to start with one outer if/else,
// using comments as placeholders for the inner if/else:

while(true) {
var enemy = hero.findNearestEnemy();
// If there is an enemy, then…
if(enemy) {
// Create a distance variable with distanceTo.
var dte = hero.distanceTo(enemy);
// If the distance is less than 5 meters, then attack.
if (dte < 5) {
hero.attack(enemy);
}
// Else (the enemy is far away), then shield.
} else {
var dte = hero.distanceTo(enemy);
if (dte > 5) {
hero.shield();
}
// Else (there is no enemy)…
} else { ERROR HERE AGAIN
// … then move back to the X.
hero.moveXY(40, 34);
}
}

Tried this and still no luck


#4

OK THIS WORKED but now I am not living lol, is it because I need the shield that is not equip-able by rangers on a ranger level? Also I feel this is kind of unfair right now because I can not get gems from simulating games but am required to buy more equipment again on a level that I should be able to complete if I could use a shield like the level requests and my code states.

I Have no clue how to do this spoiler, details thing so WARNING SPOILER AHEAD

[details=testing testing 123]
[details=
// You can put one if-statement within another if-statement.
// Be careful how the if statements interact with each other.
// It’s helpful to start with one outer if/else,
// using comments as placeholders for the inner if/else:

while(true) {
var enemy = hero.findNearestEnemy();
// If there is an enemy, then…
if(enemy) {
// Create a distance variable with distanceTo.
var dte = hero.distanceTo(enemy);
// If the distance is less than 5 meters, then attack.
if (dte < 5) {
hero.attack(enemy);
}
// Else (the enemy is far away), then shield.
} else {
if (dte > 5) {
hero.shield();
}
// Else (there is no enemy)…
else {
// … then move back to the X.
hero.moveXY(40, 34);
}
}
}
/]


#5

ok reply again again again again

I figured out how to change characters! You can’t do it like usual on the map, you have to be in the level and chose change hero or it will just default to ranger. So now I have a shield but there is still something wrong with my code lol working on a solution now =)