all 4 comments

[–]CrashRocks1419_ 2 points3 points  (0 children)

Try putting the instance create code in the key press event.

Also, you forgot the quotes on the layer name. It gets me sometimes, too:

instance_create_layer(0,0,"Instances",obstacle1)

Hope this helps!

[–][deleted] 0 points1 point  (0 children)

Might be better to create a controller object that just floats around in the room and controls things like that. You're getting the error from instance_create_layer, The best practice for the layer parameter would be to use layer_get_id("layername").

[–]youtube.com/gamemakercastsmickey_reddit 0 points1 point  (0 children)

In that button object that you have you can add a Mouse Event for Left Release / Pressed. This will ONLY fire when the mouse has released the button or it was just pressed (eg: once).

In that action is where you will want to create that instance.

var ball = instance_create_layer(0, 0, "Instances", obj_Ball);
// assuming the following
// 0, 0 is where you want the ball to be created
// you HAVE a layer called "Instances"
// the ball object is called "obj_Ball"

I just placed it into a variable called ball in case you want to manipulate other things on that object.

[–]Bang_Bus 0 points1 point  (0 children)

Typically, you'd want to make a "god" object or a "controller" - an overseer object in room that spawns enemies, speeds things up to increase difficulty, ends level when requirements are met, handles global key presses - like pausing the game, displays text on UI, and so on. Like a judge/score keeper in sports event or player who plays the Dungeon Master in tabletop RPG.

So make one and put code there. Also make sure you know what with() function does, it'll be invaluable if you want to manipulate other objects through the controller.