Don't Touch Them (JavaScript)

If it’s capitalized the code reads an error?

Replace all the true with True, and replace all the false with False.

Also if capitalizing it gives you an error, then why do you have this?

This is what it shows me if I change them all to capital. If I change the one in the while true loop it gives me an error immediately and won’t let me play the game.

Then change all of them to lowercase.

I’ve done that multiple times and I just did again. Still no success:

@jdad i have been trough all the topic…If im not mistaken then the problem here is that you defeat more then 7 scouts but your game goal is not complete.

you don’t take away the

` ` `

these things are happening to me too

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

1 Like

in the while (true) } loops its cap i think but in game.setGoalState(dontTouchGoal) its lower case

not for javascript, the “true” is lower case

ok cause i normally do python, i know a little javascript

function createGenerator(spawnType, x, y, spawnAI) {
var generator = game.spawnXY(“generator”, x, y);
generator.spawnType = spawnType;
generator.spawnAI = spawnAI;
}

// Scouts are aggressive and munchkins are just walking.
createGenerator(“scout”, 12, 12, “AttacksNearest”);
createGenerator(“scout”, 68, 56, “AttacksNearest”);
createGenerator(“munchkin”, 12, 56, “Scampers”);
createGenerator(“munchkin”, 68, 12, “Scampers”);

var player = game.spawnPlayerXY(“duelist”, 40, 34);
player.maxHealth = 1000;
player.attackDamage = 20;
player.maxSpeed = 20;

// These are our goals. Notice we save them in variables!
var spawnMunchkinsGoal = game.addManualGoal(“Let 6 munchkins spawn.”);
var dontTouchGoal = game.addManualGoal(“Don’t attack munchkins.”);
var defeatScoutsGoal = game.addManualGoal(“Defeat 6 scouts.”);
// game properties used to count new and defeated ogres.
game.spawnedMunchkins = 0;
game.defeatedScouts = 0;
game.successGoal = 0;
ui.track(game, “spawnedMunchkins”);
ui.track(game, “defeatedScouts”);

function onSpawn(event) {
game.spawnedMunchkins += 1;
}

function onDefeat(event) {
var unit = event.target;
if (unit.type == “scout”) {
game.defeatedScouts += 1;
}
if (unit.type == “munchkin”) {
// dontTouchGoal is failed if a munchkin is defeated.
game.setGoalState(dontTouchGoal, false);
player.say(“Oops.”);
}
}

function checkGoals() {
// If game.defeatedScouts is greater than 5:
if (game.defeatedScouts > 5) {
// Set defeatScoutsGoal state as successful…
game.setGoalState(defeatScoutsGoal, true);
}
// If game.spawnedMunchkins is greater than 5:
if (game.spawnMunchkins > 5) {
// Set spawnMunchkinsGoal state as successful…
game.setGoalState(spawnMunchkinsGoal, True);
}
// If both other goals are completed.
if (spawnMunchkinsGoal.success) {
if (defeatScoutsGoal.success) {
// Set dontTouchGoal state as successful…
game.setGoalState(dontTouchGoal, true);
}
}
}

game.setActionFor(“munchkin”, “spawn”, onSpawn);
game.setActionFor(“munchkin”, “defeat”, onDefeat);
game.setActionFor(“scout”, “defeat”, onDefeat);

while (true) {
checkGoals();
}

this is what i currently have an it keeps getting stuck and not letting me complete the level. im not sure what i’m doing wrong.

i haven’t done this level in javascript but look at your indentation, it needs some fixing

1 Like

so do you have any suggestions on what to indent?

umm every line after an if statement and the line under while(true){