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

Get help using Construct 2

Post » Thu Jan 01, 2015 7:18 pm

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?
Last edited by locohost on Thu Jan 01, 2015 11:13 pm, edited 1 time in total.
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Thu Jan 01, 2015 7:21 pm

Use a string and split it into an array?
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Thu Jan 01, 2015 7:40 pm

Somebody wrote: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.
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Thu Jan 01, 2015 7:53 pm

locohost wrote:
Somebody wrote: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?
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Thu Jan 01, 2015 8:57 pm

You can use a Container to attach an Array to a Sprite.
ImageImageImage
B
71
S
22
G
249
Posts: 3,764
Reputation: 138,579

Post » Thu Jan 01, 2015 10:03 pm

blackhornet wrote: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...
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Thu Jan 01, 2015 10:09 pm

+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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Jan 01, 2015 10:13 pm

locohost wrote:
blackhornet wrote: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.
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Thu Jan 01, 2015 10:14 pm

codah wrote:+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 ;)
B
14
S
4
Posts: 297
Reputation: 1,637

Post » Thu Jan 01, 2015 10:15 pm

codah wrote:+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" :?
B
14
S
4
Posts: 297
Reputation: 1,637

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 10 guests