1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

how do i create a instance

Discussion in 'Programming' started by Wyatt Putman, Apr 12, 2019.

  1. Wyatt Putman

    Wyatt Putman Member

    Joined:
    Apr 10, 2019
    Posts:
    6
    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.
     
  2. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    111
    instance_create(x,y,obj_bullet) or whatever you call the bullet object
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,694
    See: instance_create_layer()

    Also, if you're starting out, it's no time to be screwing around with major version-to-version differences. Start learning with an on-version tutorial like this one.
     
    Cloaked Games likes this.
  4. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    111
    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 );
     
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,760
    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).

    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.
     
  6. chorrus

    chorrus Member

    Joined:
    Jun 21, 2016
    Posts:
    111
    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!:)
     
  7. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    989
    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
     
  8. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,760
    Layers are actually the standard. The depth manual page states the following:
    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.
     
  9. dannyjenn

    dannyjenn Member

    Joined:
    Jul 29, 2017
    Posts:
    571
    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).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice