GMS 2 programming instances after their creation

Discussion in 'Programming' started by Sean Catherine, Jul 11, 2019 at 9:18 PM.

  1. Sean Catherine

    Sean Catherine Member

    Joined:
    Nov 10, 2017
    Posts:
    148
    If I were to create numerous instances of an object (which has no programming), would I then be able to program that one object later on, thus effecting all of its instances with that programming...? I ask because the manual cautions that this may not always work.

    Also: If I were to have an object in a room and then duplicate that room numerous times, would those duplicated rooms contain regular instances of that original object, or would those instances be something diferent somehow.

    thx
     
  2. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    616
    If you add instances of an object to a room, and then later edit that object, all the changes are automatically reflected on the instances already placed in the rooms, so no worries (if that’s what you are asking about). I have no idea where or why the manual would say otherwise.

    You are looking at things the wrong way though. Instances only exist at run time, and are based on the object (like a blueprint) as it is defined when running the game. When placing them in a room you are not actually creating instances, you are simply saying “when the game is run and the room entered, create some instances at these locations”.

    This should also answer your second question as well.
     
  3. Sean Catherine

    Sean Catherine Member

    Joined:
    Nov 10, 2017
    Posts:
    148
    Thanks for that. Here's that info that I was referring to:
    There are also a number of functions that permit you set the properties for an object. It should be noted that any instances of this object that already exist in the room may not be affected by these functions, but all new instances of this object created in the room will be, so it is recommend that you never change an objects properties when instances of that object are present in the current room.

    1. object_set_depth
    2. object_set_mask
    3. object_set_persistent
    4. object_set_solid
    5. object_set_sprite
    6. object_set_visible
    This was what worried me. Could you explain the difference between what you said vs this —confused...
     
  4. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    616
    The phrase refers to changing the object properties using those functions while the game is running.

    Simple example: suppose that you have obj_enemy that is set to visible, and while playing you create a couple of instances of that object using instance_create. Later, you call object_set_visible(obj_enemy, false).
    This does not make the enemies currently in the room invisible, but changes the “blueprint” for the new ones, so from now on new instances of obj_enemy when created will be invisible (until you close the game or use obj_set_visible again).

    Note that all the above, as said, applies only at runtime.

    I am unsure though if entering a room with instances defined through the room editor will consider those as “new” and get created invisible as well (i think so) but should be easy enough to test.
     
    Phil Strahl and Bentley like this.
  5. Sean Catherine

    Sean Catherine Member

    Joined:
    Nov 10, 2017
    Posts:
    148
    OOOHHHHHHHHHHH...
     
  6. jr carey

    jr carey Member

    Joined:
    Sep 22, 2016
    Posts:
    163
    a different way to achieve this is by using the instance ID and changing variables, like:

    time = 50
    var inst = instance_create(x,y,instance)
    var inst2 = instance_create(x,y,instance)
    inst.time = 10
    inst2.time = 900
     

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