[Solved] Storing an Array of data in each Sprite instance?

0 favourites
  • 14 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • I need to store and array of path destinations as well as some other instance specific game data. Easily accomplished in plain Javascript, but since C2 instance variables can only be numbers or strings, how can we do this?

  • Use a string and split it into an array?

  • Use a string and split it into an array?

    Yeah I had that thought too, but it would be tough to manipulate (add/edit) the data in each "cell" during runtime.

    I'm working on an idea which prompts a related question: When I use System.CreateObject, how can I catch the newly created objects UID? My thought is in the Person.onCreate, I create and Array object, catch the UID and store that in the Person in an instance variable. Now I can keep an array of data for every Person instance and find it quickly.

  • > Use a string and split it into an array?

    >

    Yeah I had that thought too, but it would be tough to manipulate (add/edit) the data in each "cell" during runtime.

    I'm working on an idea which prompts a related question: When I use System.CreateObject, how can I catch the newly created objects UID? My thought is in the Person.onCreate, I create and Array object, catch the UID and store that in the Person in an instance variable. Now I can keep an array of data for every Person instance and find it quickly.

    This seems hacktastic but perhaps this is the only way: In Array.onCreate, store it's new UID in a global var. Now when I create the array in Person.onCreate, I can get the new Array.UID. Is there an easier/smarter way to do this?

  • You can use a Container to attach an Array to a Sprite.

  • You can use a Container to attach an Array to a Sprite.

    Interesting. Didn't think of that. Let me see what this can do...

  • +1 for Container, it's exactly what you want. Even if you didn't have Containers, you could just store an ID or UID to index into a separate array per sprite instance.

  • > You can use a Container to attach an Array to a Sprite.

    >

    Interesting. Didn't think of that. Let me see what this can do...

    Containers allow objects to be grouped together and then act as one object when creating and destroying. The Container does not provide a way to easily/directly reference child objects.

    What we really need is to be able to add an Array as an instance variable in a Sprite. But we can't do this so I'm trying to figure out some way to hack this together.

  • +1 for Container, it's exactly what you want. Even if you didn't have Containers, you could just store an ID or UID to index into a separate array per sprite instance.

    This is what I'm working on

  • +1 for Container, it's exactly what you want. Even if you didn't have Containers, you could just store an ID or UID to index into a separate array per sprite instance.

    I don't see any way to reference a contained child object from the parent container so I'm not sure how "Container, it's exactly what I want"

  • You don't need to reference it, it is automatically Picked, when the Sprite is picked. You just go ahead and use it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Because when you pick an object, it's 'contained' objects are automatically picked, so you can just reference it.

  • Ahhh Ok then! Thanks guys!

  • Yep, working well. Adding an Array as a contained object in the Person sprite is the answer. Thank you, thank you, thank you guys!

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