How do I store an instance in a variable?

  • In my game a work with many sprites and it would really help if I can save a sprite instance in a variable. I haven't found any solution to this.

    /dag

  • You may need a better explanation of what you want to do.

  • As a professional developer am I used to store objects, not only strings and numbers, in a variable. Maybe I am thinking wrong what can be done in Construct?

    I know of course about the different Pick events you can do. I use them rather often. I also use Rex Instance Group (which is great).

    What I want to do is to compare from a big group of Sprites different things and see if they match. I know that it probably can be done in different way, but I really like to be able to store an instance of a sprite and then be able to get all properties for that sprite.

    /dag

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No, not the UID, this is a property of an instance. (But it is good to identify an instance.) I want the instance itself.

  • Sorry guys. Maybe I am not thinking the right "construct 2 way". Thats why I ask.

  • You cannot store an instance of an object (e.g. sprites) as with traditional OO languages (like have an array of them or something)... I believe there are third party plugins like 'instance bank' or something but I'm not sure if they do what you want. Usually the UID is stored, which can then be used to 'pick' the instance. But it's not the same thing.

    Bottom line is no, you're not thinking the C2 way yet

  • Thanks, then I know. I have to do this differently.

    /dag

  • buzzfrog

    maybe this will help you.

  • Thanks

    I will check it out.

    /dag

  • FYI

    That I can have an index on instances can help me. I did not know that before.

    [quote:2i7ld4a1]You can add a 0-based object index to get expressions from different object instances. For example Sprite(0).X gets the first Sprite instance's X position, and Sprite(1).X gets the second instance's X position. For more information see index IDs (IIDs) in common features. You can also pass another expression for the index. Negative numbers start from the opposite end, so Sprite(-1).X gets the last Sprite's X position.

    https://www.scirra.com/manual/78/expressions

  • I've found it useful to use the IID occasionally but I forgot you could index sprites like that. Thanks for the reminder.

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