How do I reference an object in an instance variable?

0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have a family of sprites. I need to be able to create a particular one as indicated by the instance variable of another object. But I can't find any way to directly store an object reference in an instance variable. The best I've come up with so far is this:

    [attachment=0:2cu15kz1][/attachment:2cu15kz1]

    That works just fine, but I'm going to have over a hundred sprites in the family. Which means this sort of manual look-up table is going to get really unwieldy.

    Does anyone have any thoughts about a better way to do this?

    Thanks!

  • Maybe this could help..

  • Maybe this could help..

    Thanks for the tip!

    That looks like it might be just what I need. I can create an instance from its nickname. However, so far I can't figure out how to get the UID of the instance that was created. Do you happen to know how to do that?

  • Try this, not sure if its what you want though.

  • Try this, not sure if its what you want though.

    Thank you for the effort.

    Here's what I'm trying to do:

    [attachment=1:2mq55056][/attachment:2mq55056]

    This creates a new instance of Sprite which was nicknamed "Monster", which is exactly what I wanted. However, now that I've created it, I need a reference to it so that I can work with it. So I need the UID or some other way of picking it.

    Example attached.

    Thanks again!

  • Pick it by largest IID maybe?

  • Pick it by largest IID maybe?

    Unfortunately, I don't have any way of knowing what object the instance was created from. So I wouldn't know what to search for an IID. At the time of creation, this "nickname" is all I have.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Whats wrong with this then ?

    You can store the UID of the sprite anywhere you like. Maybe i am just thick and not understanding the problem here.

  • Whats wrong with this then ?

    The trouble was that Sprite could actually be a great many different objects, so I couldn't reference them collectively that way. However, your proposal got me looking over things again, and I realized that I'd been a total idiot! The nickname plugin offers exactly the condition that I needed:

    [attachment=1:1t4xufkl][/attachment:1t4xufkl]

    Voila! All I needed was to have all possible sprites in a family (which they already were) and then use the nickname picker (that I somehow overlooked like five times yesterday) to select it.

    Thanks so much for your help! This will save me a great deal of effort.

  • Right i see what you needed now. Glad you figured it out

  • Gah! After all that, it turns out the Nickname addons only work when you already have at least one instance of the tagged objects on the layout. Which isn't at all workable for my scenario. Alas.

    So if anyone else has any thoughts on how to store an object reference in an instance variable, I'd love to hear them!

    Until then, I'm back to my ever-growing lookup table.

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