Why does the pet.on("spawn", onSpawn) code run continuously?


#1

The following code runs continuously even though the spawn event only happens once at the beginning of the stage. I see the while loop as part of the function but does that while loop cause the pet.on(“spawn”, onSpawn) to run continuously?

function onSpawn(event) {
    while (true) {
        // Pets can find enemies, too.
        var enemy = pet.findNearestEnemy();
        // If there is an enemy:
        if (enemy) {
            pet.say("Get to da choppa!!");
        }
            // Then have the pet say something:
            
    }
}
pet.on("spawn", onSpawn);

#2
pet.on("spawn", onSpawn);

Is one time event

But this part of onSpawn() will running until the end of level

while (true) {
        // Pets can find enemies, too.
        var enemy = pet.findNearestEnemy();
        // If there is an enemy:
        if (enemy) {
            pet.say("Get to da choppa!!");
        }
}

#3

Got it. Thanks.

By the way, I love watching replays of your records - very creative approaches. I only wish I got to see your records when they’re in the top 5 of a level.

I’m not a big fan of this current system where we can’t see the top 5. I think it’ll be more educational to look at the best, most creative codes and take inspiration from that


#4

Thanks.
I wish to see top 5 too.
But it will make the idea of leaderboard pointless.

Thx to bugs. You can watch top 5 for many levels anyway. Plus if level have multiple leaderboards. You can check other tabs.