how do i create a instance

W

Wyatt Putman

Guest
i am trying to make a top down shooter in gml, i've made all the movement and rotation but i don't know how to make the player shoot, i saw tutorials online and all of them said to use the function "instance_create" but every time i use that it just says it is a variable and it says nowhere that it is an actual function. i am using GMS2 if you could help me out and tell me what function to use and how to use it that would be greatly appreciated.
 

chorrus

Member
Oh yeah, they removed instance_create in GMS:2. However I keep using it adding this script.
It's probably a good idea to use their new system but I like the last one better(or at least I am way too used to it).

Create an script and name it instance_create then copy this code:
/// @description Creates an instance of a given object at a given position.
/// @param x The x position the object will be created at.
/// @param y The y position the object will be created at.
/// @param obj The object to create an instance of.
var myDepth = object_get_depth( argument2 );
return instance_create_depth( argument0, argument1, myDepth, argument2 );
 

TsukaYuriko

☄️
Forum Staff
Moderator
Oh yeah, they removed instance_create in GMS:2. However I keep using it adding this script.
It's probably a good idea to use their new system but I like the last one better(or at least I am way too used to it).

Create an script and name it instance_create then copy this code:
/// @description Creates an instance of a given object at a given position.
/// @param x The x position the object will be created at.
/// @param y The y position the object will be created at.
/// @param obj The object to create an instance of.
var myDepth = object_get_depth( argument2 );
return instance_create_depth( argument0, argument1, myDepth, argument2 );
Careful - you're jumping from one obsolete function (instance_create) to the other (object_get_depth). There is no depth setting in the object editor anymore, and it's not recognized as a function in the current version (IDE 2.2.2.413, runtime 2.2.2.326).

i am trying to make a top down shooter in gml, i've made all the movement and rotation but i don't know how to make the player shoot, i saw tutorials online and all of them said to use the function "instance_create" but every time i use that it just says it is a variable and it says nowhere that it is an actual function. i am using GMS2 if you could help me out and tell me what function to use and how to use it that would be greatly appreciated.
This topic is a perfect example of why one must take great care to pay attention to the software version being used. I can only recommend to always ensure that the content you are following is suitable for what you're using - as you can see, not doing so has a tendency to result in additional issues on top of what you were originally trying to solve.

I suggest familiarizing yourself with the term "layers" at least on a fundamental level (manual: The Room Editor, Layers section) - not because your issue requires using them, just so you won't be using a feature that you don't have basic understanding of - and using instance_create_layer as @FrostyCat mentioned before, as this is the current standard practice. Using an up-to-date learning resource will help greatly to reduce the likelihood of further unnecessary complications.
 

chorrus

Member
Careful - you're jumping from one obsolete function (instance_create) to the other (object_get_depth). There is no depth setting in the object editor anymore, and it's not recognized as a function in the current version (IDE 2.2.2.413, runtime 2.2.2.326).
Damn, most of the projects I'm working on were started in GM:S 1, the compatibility scripts work so well I haven't even noticed some of the basic functions like those have been changed:D
However thanks for pointing it out!:)
 

Joe Ellis

Member
instance_create_depth is the standard one isn't it? its basically instance_create_3d(x, y, z) the layers are optional to use, and you shouldn't recommend that everyone uses them
 

TsukaYuriko

☄️
Forum Staff
Moderator
Layers are actually the standard. The depth manual page states the following:
You would normally not need to use this variable as you should be setting instances to be added to discreet layers
As far as I'm aware, depth variations of functions are included mainly for backwards compatibility and for integration of compatibility scripts. Layers are the way to go.
 
D

dannyjenn

Guest
Regarding the OP - In case you're not aware, there is a help file which lists all the functions and how they're used. You can view the help file through the help menu in the IDE. It's also online at http://docs2.yoyogames.com (as FrostyCat alluded to).
 
Top