GML Get objects within a project

Discussion in 'Programming' started by steveyg90, Apr 19, 2019.

  1. steveyg90

    steveyg90 Member

    Joined:
    Feb 27, 2017
    Posts:
    124
    Hi,

    I want to iterate through all the objects in my GMS2 project and then display these onto the screen were the user can then select them and move them to a place on the screen. Is there a way to do this in code without me having to just add the objects myself manually? If I can't do this I was thinking of just using the sprite images for these objects and then look up table to determine which object the sprite is associated with.

    Any advice is appreciated.
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,036
    Objects IDs in GMS 2 run from 0 up with no gaps, so you can just loop until object_exists() says no.
    Code:
    for (var obj = 0; object_exists(obj); obj++) {
      //...
    }
    
    There will probably be some exceptions that you don't want your end user to get at (e.g. controller objects), but you can handle that on a case-by-case basis.
     
    Bentley likes this.
  3. steveyg90

    steveyg90 Member

    Joined:
    Feb 27, 2017
    Posts:
    124
    Hey that seems simple enough, will give it a go but issue I see would be it would add every object, just want to add enemy objects so not sure how to filter. At the moment I've just created a list and added the objects in there manually.
     

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