Legacy GM Making preset instance creations

M

MrPerson561

Guest
Hello, all. I'm trying to make an infinite runner game. This is a little hard to explain, but the way I am attempting to do this is to have preset obstacles then create a random one in front of the player every few seconds. What would be the best way to do this? The only way I could think of would be to have a script with a bunch of "instance_create"'s (which is probably a terrible idea). Keep in mind I'm still somewhat new to GM:S so don't hate me if the answer is really obvious :p
 

TheouAegis

Member
Make an array holding all of the object_index values to create. Pick a random index in the array when you want to spawn an obstacle and reference the array to get the object_index to spawn.
 
M

MrPerson561

Guest
I'm sorry, maybe I didn't make this clear enough in the question or maybe I didn't understand your answer right, but each obstacle would be more than one instance (and possibly more than one different object), so the problem is to spawn all of them at once without having a million "instance_create"s. :confused:
 
Sorry. If you want to create multiple instances, you're going to have to call multiple 'instance_create' lines. If you set up a series of arrays with object IDs and relative x/y coordinates, then you can spawn the instances using a loop, but that's about it.
 

TheouAegis

Member
Make a 2D array holding all the enemy waves in the first index and store all the x/y pairs and object_index in the other index in order: x, y, object_index. To start your loop, retrieve the length of the wave index of the 2D array.

var limit = array_length_2D(enemylist, wave);
var i=0;
while i<limit
instance_create(enemylist[wave,i++], enemy_list[wave,i++], enemy_list[wave,i++]);
 
Top