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)
Hi @Allan_Jiang and welcome to the forum!
// 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();
}
Please, format it how it is described here so we can help you.
i am confused how to format
You did not succed. Please try to format it as it is explaned in the topic I sent you.
Here put the code.
This is how your code should appear.
// 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();
}
Congratulations! You did it right this time!
Yay! I’m just gonna wait for my corrections.
Here put
game.addSurviveGoal(30);
Instead
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.
Yes, but the comments told you to set it to 30. The rest looks all right. Can you tell me your problem again?
How often do the throwers spawn?
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?
ok its good now, thank you for helping.
No problem! Glad I could help you! And congratulations for completing the level!