How do I Return An Object Name

  • What I'm trying to do:

    sprite.click() {
    textBox.text = this.objectName
    }[/code:812gmlgi]
    I can see there's a .layerName expression but I can't find anything along the lines of .objectName or .spriteName - is there a way to automatically set the instance variable to the object name instead? Setting them manually isn't an option due to the vast number.
    
    Thanks.
  • you could do it like this

  • Thanks for the capx - but did you change the animation names manually?

  • What you do is go into Animation Editor and on right side there is box where you can type animation. Type name here or open my capx and double click blue or green box. This should help you because by name of animation name is Default. Just type your chosen name

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Unfortunately, I have too many sprites to set manually, which is why I need a way to retrieve the object names.

  • Yes but every sprite has animation is it not? Even every time you add sprite you import the IMAGES yes?

  • The default animation name for each added sprite will always be 'default' though.

    There are many ways I can manually tag each sprite individually - I'm asking if there's a means to avoid this.

  • I always wondered why there wasn't any mean to retrieve the type name at runtime. It's not like the variable isn't there...

    Using the Browser object's ExecJS expression, you can easily retrieve it though, it's just unconvenient.

  • Magistross It wouldn't work after export though would it?

    I think the reason you can't get the object name is because they are obfuscated at export. Same reason we can't create an object by name.

  • ramones It certainly won't work after obfuscating. It would still work though if we created a behavior with the sole purpose of providing an expression to retrieve the instance type name. Variable names get obfuscated, but string literals doesn't.

  • I always wondered why there wasn't any mean to retrieve the type name at runtime. It's not like the variable isn't there...

    Using the Browser object's ExecJS expression, you can easily retrieve it though, it's just unconvenient.

    Thank you! That works a treat

    Yes - it is odd that it's not included. It's a feature that I would have benefited from many times before now. Feature request?

  • simplisto ramones I just tried creating a simple plugin to retrieve the type name and it seems I was wrong. Type names get aliased on publish (with or without minifying), to something like "t0", "t1", "t2"... It seems using your own instance variable is the only way. Guess it's back to the drawing board for you simplisto.

  • Yeah - I just tried it once published and all I get is zeros. What a pain

    I'd love to hear from Ashley on this one.

  • That's why it's not included, it's obfuscated at export-time to help prevent reverse engineering of your projects.

    Just use an instance variable with the object name.

  • That's why it's not included, it's obfuscated at export-time to help prevent reverse engineering of your projects.

    Just use an instance variable with the object name.

    That's what I do, also makes it easier to use one sprite, multiple image frames and name them multiple things...

    Blue, red, green, etc etc and can do it via array or start of layout... much more flexible.

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