[SOLVED] Game Development 2: Level 11

I have a hard time figuring out how to solve it so im wondering if anybody could help, the problem is that i keep spawning way too much throwers than i need to. (language is java script)

2 Likes

Hi @Allan_Jiang and welcome to the forum! :slightly_smiling_face: :partying_face:

Could you send us your code formated how it is described here so we will be able to help?
2 Likes

// Use timers to spawn enemies and items.

// This spawns two aggressive munchkins.
function spawnMunchkins() {
var munchkin1 = game.spawnXY(“munchkin”, 2, 12);
var munchkin2 = game.spawnXY(“munchkin”, 2, 56);
munchkin1.behavior = “AttacksNearest”;
munchkin2.behavior = “AttacksNearest”;
}

// This spawns two aggressive throwers.
function spawnThrowers() {
var thrower1 = game.spawnXY(“thrower”, 2, 16);
var thrower2 = game.spawnXY(“thrower”, 2, 52);
thrower1.behavior = “AttacksNearest”;
thrower2.behavior = “AttacksNearest”;
}

// This spawns a health potion near the village.
function spawnPotion() {
game.spawnXY(“potion-large”, 46, 34);
}

// Survive 30 seconds.
game.addSurviveGoal(20);

// The inital values of timers define the first appearance.
game.munchkinSpawnTime = 0;
game.throwerSpawnTime = 0;
game.potionSpawnTime = 6;
// This is used for UI.
game.nextPotionIn = 0;

ui.track(game, “time”);
// Lets show how long until the next potion.
ui.track(game, “nextPotionIn”);

var player = game.spawnPlayerXY(“duelist”, 40, 34);
player.maxSpeed = 15;

// This checks and updates timers.
function updateTimers() {
// If game time is greater than the munchkinSpawnTime
if (game.time > game.munchkinSpawnTime) {
// Update the timer and spawn the munchkins.
game.munchkinSpawnTime = game.munchkinSpawnTime + 6;
spawnMunchkins();
}
// If game time is greater than potionSpawnTime
if (game.time > game.potionSpawnTime) {
player.say(“The potion is here!”);
// Increase game.potionSpawnTime by 6:
game.potionSpawnTime = game.potionSpawnTime + 6;
// Call the spawnPotion function:
spawnPotion();
}
// If game time is greater than throwerSpawnTime:
if (game.time > game.throwerSpawnTime) {
// Increase game.throwerSpawnTime by 9:
game.throwerSpawmTime = game.throwerSpawnTime + 9;
// Call the spawnThrowers function:
spawnThrowers();
}
// Update the UI timer until the next potion
game.nextPotionIn = game.potionSpawnTime - game.time;
}

while (true) {
updateTimers();
}

1 Like

Please, format it how it is described here so we can help you.

1 Like

i am confused how to format

1 Like

You did not succed. Please try to format it as it is explaned in the topic I sent you.

2 Likes
Here put the code.

This is how your code should appear.

2 Likes
// Use timers to spawn enemies and items.

// This spawns two aggressive munchkins.
function spawnMunchkins() {
    var munchkin1 = game.spawnXY("munchkin", 2, 12);
    var munchkin2 = game.spawnXY("munchkin", 2, 56);
    munchkin1.behavior = "AttacksNearest";
    munchkin2.behavior = "AttacksNearest";
}

// This spawns two aggressive throwers
function spawnThrowers() {
    var thrower1 = game.spawnXY("thrower", 2, 16);
    var thrower2 = game.spawnXY("thrower", 2, 52);
    thrower1.behavior = "AttacksNearest";
    thrower2.behavior = "AttacksNearest";
}

// This spawns a health potion near the village.
function spawnPotion() {
    game.spawnXY("potion-large", 46, 34);
}

// Survive 30 seconds.
game.addSurviveGoal(20);

// The inital values of timers define the first appearance.
game.munchkinSpawnTime = 0;
game.throwerSpawnTime = 0;
game.potionSpawnTime = 6;
// This is used for UI.
game.nextPotionIn = 0;

ui.track(game, "time");
// Lets show how long until the next potion.
ui.track(game, "nextPotionIn");

var player = game.spawnPlayerXY("duelist", 40, 34);
player.maxSpeed = 15;

// This checks and updates timers.
function updateTimers() {
    // If game time is greater than the munchkinSpawnTime
    if (game.time > game.munchkinSpawnTime) {
        // Update the timer and spawn the munchkins.
        game.munchkinSpawnTime = game.munchkinSpawnTime + 6;
        spawnMunchkins();
    }
    // If game time is greater than potionSpawnTime
    if (game.time > game.potionSpawnTime) {
        player.say("The potion is here!");
        // Increase game.potionSpawnTime by 6:
        game.potionSpawnTime = game.potionSpawnTime + 6;
        // Call the spawnPotion function:
        spawnPotion();
    }
    // If game time is greater than throwerSpawnTime:
     if (game.time > game.throwerSpawnTime) {
        // Increase game.throwerSpawnTime by 9:
        game.throwerSpawmTime = game.throwerSpawnTime + 9;
        // Call the spawnThrowers function:
        spawnThrowers();
     }
    // Update the UI timer until the next potion
    game.nextPotionIn = game.potionSpawnTime - game.time;
}
    
while (true) {
    updateTimers();
}

1 Like

Congratulations! You did it right this time!

2 Likes

Yay! I’m just gonna wait for my corrections.

1 Like

Here put

game.addSurviveGoal(30);

Instead

2 Likes

doesn’t that just increase the time i need to survive?

and the problem i have is that i keep spawning way to much throwers.

1 Like

Yes, but the comments told you to set it to 30. The rest looks all right. Can you tell me your problem again?

1 Like

How often do the throwers spawn?

2 Likes

I keep spawning like 100 throwers every time

Check your spelling! It is Spawn, not Spawm.
Do you need any more assistance at this level?

2 Likes

ok its good now, thank you for helping.

2 Likes

No problem! Glad I could help you! And congratulations for completing the level! :slightly_smiling_face: :partying_face:

2 Likes