Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Web Development 2 Level: Teatime HELP (SOLVED)


whenever im trying to spawn in throwers it just spams so much and i was wondering if this was supposed to happen but i went over the code and its supposed to send out 2 throwers and i was wondering if anyone could help?

this is my code

// 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.

// 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;
    // 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:
    // If game time is greater than throwerSpawnTime:
    if (game.time > game.throwerSpawnTime) 
        // Increase game.throwerSpawnTime by 9:
        game.throwerSpawnTime = game.throwerSpawnTime + 7;
        // Call the spawnThrowers function:
    // Update the UI timer until the next potion
    game.nextPotionIn = game.potionSpawnTime - game.time;
while (true) {

UPDATE: i redid my code but it still hasnt worked at all but i hope people can view it much more easier.


Alright so. I have only done a little bit of Web Development but I think what the issue is is that in the code that I quoted, you are spawning additional throwers. But you are also spawning them in the loop for your overall code.


So how can I not make them go in a loop and not spawn so much? Because all I’m doing is putting in the code. I still need some help.


You have missing braces:
Put the braces and the required code after the fleshes. Don’t change the original code. You have too many editions in your first post and I cannot keep track of all of them.