Selecting objects based on their name

  • Hi,

    I have a variable with which I'd like to be able to select different kinds of objects based on what's specified. Is there any way to target objects based on their name?

  • Maybe create a name variable for that objects, and then write:

    if object.variable == "name" to choose that object

  • That's what I'm trying to do, but how do I do that? I can't find any relevant event triggers.

  • To help obfuscate your project so it is difficult to reverse engineer, all object names are removed from the project when you export it. This is why there are no features to use the object names: they are not there after export.

    The best workaround is to add an instance variable which you manually set to the object's name, then access that.

  • That's a good idea, but how can I access those instance variables then? It doesn't seem like I can do a foreach for every sprite object that exists in my game, or can I?

  • yeah you can actually...

    add a For Each loop then pick your object you want to loop thru then inside the loop do a Compare Instance Variable and see if its Name instance variable (that you added to the object) matches the one your lookin for.

    I do this all time. Its how I avoid adding multiples of the same object like Text objects. I just add one and add a Tag instance var then use that tag to set the text for specific ones

  • Your example would only compare the loop to *one* object.

    I want to compare a value with the instance variable of ALL objects, until i find a match. :-)

  • this example shows you how to compare multiple objects by varname

    by looping tru a family of objects and comparing the namevar

    comparename

    does this help?

  • It does. Thanks a lot! :-)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley:

    In which way are the objects renamed on export? Is there some kind of pattern used? Are the same objects always renamed the same way on export?

    The reason why I'm asking is that I've created a level editor that saves the sprites using the SpriteBank-plugin. The plugin uses sprite names to reference to the sprites when saving, and if the naming changes when you re-export the project (for updates, for instance) it will mess up previous level saved.

    This is not a problem you should worry about - I can replace the names in the save file manually myself, but it would make my life easier if you could tell me how the renaming system works.

    Thanks!

  • basti: look at the google compiler Closure. It's the tool doing the minifying job.

    Also, SpriteBank is a third party plugin, if there are minifying issues, you should report to its author in the topic of the plugin.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)