GML Visual How can I create for example obstacle to spawn randomly out of 3 options and move down

A

Aite

Guest
Hello, sorry for the dumb question but I'm new with this kind of stuff and I really struggle with it. I'm making my own game but i don't know how to spawn out of 3 options spawn obstacle that the player who is down on the screen to move left, middle or right in order t o prevent being hit by it. I'll appreciate help!
 
That's simple!

Option 1:
Code:
var obstacle_array = [obstacle1, obstacle2, obstacle3];
var choice = i_random(2);
var obstacle = instance_create_layer(x, y, "Layer", obstacle_array[choice]);
... other stuff with the obstacle here
Option2:
Code:
var obstacle = instance_create_layer(x, y, "Layer", choose(obstacle1, obstacle2, obstacle3));
... other stuff with the obstacle here
The first option is a little easier to modify the invididual choices, but the latter is more efficient overall. In that case, you may want to use variables to reference the obstacles to choose from. Or perhaps an array, like

Code:
var obstacle_array = [obstacle1, obstacle2, obstacle3];
var obstacle = instance_create_layer(x, y, "Layer", choose(obstacle_array[0], obstacle_array[1], obstacle_array[2]));
 
Top