GML How to spawn objects from an array

T

tidlon

Guest
Hello!

What I want to do is to spawn objects randomly between 5 different spawn points , so what I am trying to do is to add an array to a spawnManager(object) that will take those spawn objects into the array and then randomly spawn an object from one of those spawn points with a timer... but I am kinda new to this.. and I basically have no clue how to make arrays work.. pls help...

the picture above is the spawnmanager(Create)

spawnmanager(Step) above image

the spawn object is on picture above (create)

the spawn object picture above (alarm0)

the actual obj_spawner works fine, it spawns objects with a cooldown, but what I want now is to have 5 of these spawners that will spawn one object every second randomly between these 5 spawners, so basically one of these spawners should spawn 1 object at a time.


in above image the purple squares are spawning from the blue spawn objects on top and going downwards.


thanks in advance! :D
 
Last edited by a moderator:

Relic

Member
Not sure about drag and drop (not many of us are).

The basic idea is you will want to choose a random spawner when your alarm goes off (an alarm in the controller, not each spawner)

Alarm 0:
  • Choose random integer from 0 through to 4
  • create instance at this spawner (instance_create_layer(index.x,index.y,"spawnedSynths",obj_synthNote_org)
    [*]reset alarm
 
T

tidlon

Guest
Not sure about drag and drop (not many of us are).

The basic idea is you will want to choose a random spawner when your alarm goes off (an alarm in the controller, not each spawner)

Alarm 0:
  • Choose random integer from 0 through to 4
  • create instance at this spawner (instance_create_layer(index.x,index.y,"spawnedSynths",obj_synthNote_org)
    [*]reset alarm
hmm, I am using DnD for a reason.. cause I am kinda new to programming... pretty much I am bad, so how do you want me to create "choose random integer from 0 through 4" ?
 

Relic

Member
I can’t use drag and drop. For that you will have to wait for someone else to jump in or just hover around all the options for drag and drop and see what you can find.
 

sylvain_l

Member
hmm, I am using DnD for a reason.. cause I am kinda new to programming...
WTF, you are already using most of the time the execute code node and writing the code instead of using the native node

back to the question, everytime someone point you to a function in GML code just try to type it or just a word of it in the filter of the node ressources; most of the nodes have the same name or very similar name to their code counterpart.
(there are a few exception, like you have a instance_create_layer node but no counter part for the instance_create_depth for what I know)

so if some one give you the choose() gml function just use the choose node, etc.

to select something randomly, choose(), irandom() there are a bunch of function available to randomly take a value.
 
T

tidlon

Guest
Ok, I kinda managed to solve the problem, but now I got another issue, I managed to make 4 out of 5 spawners spawn a synthNote, but for some reason the first spawner with ( Index = 0; ) dont want to spawn... I dont get it...

here look at some pictures..




as you can see here only the spawners index 1,2,3,4 spawns an object, the spawner to far left aka index 0 dont spawn... I dont get it
 
T

tidlon

Guest
nvm, I found the problem, it was random.range instead of irandom.range :p fml
 
Top