• 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!

Setting alarms in rooms

M

mjmiller1824

Guest
So I have a global.y, an array of global.x, and an array of objects that exist within the game scope. I'm trying to set an alarm that spawns one random object from the array every 1.25 seconds and sends it in a random direction. The motion is set in each object. So instance_create(global.spawnX[irandom_range(0,5)],global.spawnY,global.types[irandom_range(0,4)]); can call the new object. How can I call this from a room with an alarm? Or other way of doing a timer? So that one random object in the types array is called at a position in the global.spawnX array, at globalSpawnY. I'm just having trouble with the timing. Any options would be appreciated.
 
T

TaylorBramble

Guest
Since your code is working and your timing is just off:
you could just make your own alarm based off the room_speed, though idk, working in seconds is kind of weird.
spawn_alarm = 1.25*room_speed
spawn_time +=1
if (spawn_time >spawn_alarm)
{
spawn_time -= spawn_alarm
//Do your spawn code here//
}
This will get the timing a little closer, but every so often I'm assuming it'll make two at once.
 
M

mjmiller1824

Guest
Since your code is working and your timing is just off:
you could just make your own alarm based off the room_speed, though idk, working in seconds is kind of weird.
spawn_alarm = 1.25*room_speed
spawn_time +=1
if (spawn_time >spawn_alarm)
{
spawn_time -= spawn_alarm
//Do your spawn code here//
}
This will get the timing a little closer, but every so often I'm assuming it'll make two at once.
Sorry man, just thinking in cycles and player perception. So I have my rooms set to 60fps to match 60hz and 120 hz screens so 1.25 seconds= 75 cycles.. But I think TheouAegis might have it. How would I go about creating a controller object that can spawn objects across the x axis and tied to the y axis.
 
P

ParodyKnaveBob

Guest
Howdy, mjmiller1824, and welcome to GM and the GMC. $:^ J

Have you taken any of the built-in tutorials? You seem to have a firm grasp of straight-up code already yet lack basic GM usage. If you go through Catch the Clown / My First Game, it'll teach you about controllers and alarms (among many other super basics).

I hope this helps,
Bob $:^ ]
 
M

mjmiller1824

Guest
I understand setting alarms in general, but yeah I guess I'm looking for a way to set events in rooms. But you say the clown tutorial? I have taken some of the tutorials but I'm not sure I've taken the same tutorials you have....If someone could just point me to the GML manual section on controller objects? It's really just about spawning the random instances both on a timer, and accounting for when they collide with the top barrier to tell them they can spawn more instances, so it's like I want a maximum of say 10 objects in the room. Spawn [timer] spawn [timer] spawn [timer] collision [spawn] sort of process.
 
P

ParodyKnaveBob

Guest
I don't recall any "controller section" in the manual. (And I love me some manual!) It's outside its scope as far as I can tell. What you do is act like you're opening a new project in GM, but on the welcome screen, the tabs across the top? you hit the Tutorials tab. Those are the built-in tutorials. Very first one should do the trick. It's short and cute/fun. ~shrug~ $:^ J
 

TheouAegis

Member
A controller object is simply an object that holds code that controls every aspect of the game that other objects don't. You can't run code every step outside of objects in GM:Studio (you could in the legacy versions), so you need objects to handle the routines of your game. The only time you don't need an object is in the Room Creation Code, which is only run for 1 step when the room is created. The player object controls the player aspect of the game; the enemy objects control the enemy aspects of the game; the projectile objects control the projectile aspects of the game; the snozzberry object controls the snozzberry aspect of the game; and the controller objects control all other aspects of the game.
 
Top