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

Mass controlling instances

Discussion in 'Programming' started by 66Gramms, Aug 23, 2017.

  1. 66Gramms

    66Gramms Member

    Joined:
    Feb 2, 2017
    Posts:
    23
    Hello!
    So i'm making a level select screen where will be 90 levels but always 30 of them on display... (actually there are 30 instances) So i make the instances in a cycle and there i do it like this:
    Code:
    instance = instance_create(x, y, obj_level_select);
    instance.level += rise //Level is a variable inside the object that is used to display the lvl number
    rise++; 
    So this way i have levels from 1 to 30 lined up perfectly. but when i want to "change page" in the game i actually just want to change the instances' level variable by +1/-1
    to do this all the instances should have different id. I know it could be done with an array but they told me there is a better way to do that. can you please help me about how to give all of them a different id and not all of them are going to be "instance" without using arrays?

    if i don't do this just type like obj_level_select.level++ then all the instances will change to the same value (2) then increase together. Thanks in advance
     

    Attached Files:

  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,122
    The reason this doesn't work

    obj_level_select.level++

    is it counts as a read operation. It basically means

    obj_level_select.level=obj_level_select_0.level+1

    So all instances are set based on the value of one.

    with obj_level_select level++

    Do that.
     
    66Gramms likes this.
  3. 66Gramms

    66Gramms Member

    Joined:
    Feb 2, 2017
    Posts:
    23
    This is working, thank you ^^ I know why it didn't work i just didn't know how to make it work :D Also i realized i need to add 30 to them :D
     

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