Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1036720 Posts in 41859 Topics- by 33478 Members - Latest Member: deanr201

August 28, 2014, 01:13:07 AM
TIGSource ForumsDeveloperTutorialsGame maker monster spawner working once and then stopping
Pages: [1]
Print
Author Topic: Game maker monster spawner working once and then stopping  (Read 1866 times)
hobothehero
Level 0
*


View Profile
« on: January 22, 2012, 11:45:47 PM »

Ok so im making a zombie wave survival thing just to see if I can do it and I have managed to make zombies randomly spawn at the start of the game using a monster spawner which is out of sight.

The problem is there is only one wave of zombie spawns even though i believe i have set it up to have a chance to make zombies at regular intervals.

Here is the code on the create event of the zombie spawner:
"spawndelay = 0
spawnchance =ceil(random(10))"

So setting spawndelay to zero and making spawnchance a random whole number from 0 to 9.

Then this is on the step event:
"if spawndelay = 0
{
if spawnchance = 9
{instance_create (id.x,id.y,oenemy)
spawndelay = 4
spawnchance = ceil(random(10))}}
if spawndelay > 0
spawndelay -= 1"

This is where i assume something is wrong but im not sure what.

Any help would be great thanks

(I just joined because of this problem so sorry if it is in the wrong place or something)
Logged
Zack Bell
Level 10
*****



View Profile WWW
« Reply #1 on: January 23, 2012, 12:06:29 AM »

For something like this, I would probably just use Game Maker's alarms. So something more like this:

Code:
//CREATE EVENT:
canSpawn = true;

Code:
//STEP EVENT

if (canSpawn) {
    //*** Put zombie spawning code here ***
    alarm[0] = 360 + random(360);
    canSpawn = false;
}

Code:
//ALARM 0 EVENT
canSpawn = true;

You could also add a condition to check how many zombies there are...

Code:
if (canSpawn) && (instance_number(ZOMBIE) < 4) {
    //...etc
}
Logged

hobothehero
Level 0
*


View Profile
« Reply #2 on: January 23, 2012, 12:21:49 AM »

Thanks alot!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic