• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Spawning 1-5 Random Objects Every 30 minutes (solved)

S

SlothSam

Guest
Okay so, my intent is this: At the start of the game, 1-5 Objects (monsters, its a monster game) spawn randomly out of a set of 50 (right now only 2 test objects though). ((it also might be helpful to know that its a set of 50 for day and another set of 50 for night, running hopefully in real time?))
After 30 minutes, all instances of these objects are to destroyed and another set of 1-5 random objects spawned.
I've got a looping timeline to destroy the instances and pick 1 of 5 alarms (to determine if its 1, 2, 3, 4, or 5 monsters that spawn)
What I can't sleuth out is how to best get it so it does actually spawn more than 1 random monster for 4 of the alarms.
I would also like to know if the code I'm using is like, what I should be doing for this? I was looking around online for some time to find any tutorials to spawn a random object from a set and not just spawn a set object in a random location, and I think this might be what I'm looking for? I am in no way familiar with code so help and critique is greatly appreciated (im using version 1.4.1804 if that is of help)
Code:
if current_hour >= 6 and current_hour < 18 
then monster = choose(nighttest1_obj, nighttest2_obj)
else
monster = choose(Unicorn_obj, daytest1_obj, daytest2_obj)


if (spawn) { 
    instance_create(random(1024),random(768),monster);
    alarm[0] = 53999;
    spawn = false; }
 
I would move the first if inside of the if (spawn) and use a repeat to get the 5 monsters spawning, like this:
Code:
if (spawn) {
   repeat(5) {
      if (current_hour >= 6 and current_hour < 18) {
         monster = choose(nighttest1_obj, nighttest2_obj);
      }
      else {
         monster = choose(Unicorn_obj, daytest1_obj, daytest2_obj);
      }
      instance_create(random(1024),random(768),monster);
   }
   alarm[0] = 30*60*room_speed;
   spawn = false;
}
 
S

SlothSam

Guest
ahhhhhh sorry for a late response but I had to go visit family for easter and didnt get to try out the code!
But it works!!!! Thank you so much this is like, integral to my project thanks dude!!!!!!!
 
Top