assign array to object

For questions about using Classic.

Post » Thu Dec 10, 2009 11:46 am

lets say for example i have an array for holding weapon stats and a sprite which servers as my enemy. i have many enemies, each holding different weapons. i cant use the same array object for all enemies. the array object acts like a global array rather than an array i can make private to each enemy. how can i do this?
B
2
G
3
Posts: 12
Reputation: 874

Post » Thu Dec 10, 2009 12:00 pm

You can add components to your array, z for example, but that has a limitation at some point.
You can also add multiple arrays, but again that may be limiting if it takes up a lot of memory.
Probably your best bet is a private variable for the stat.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Dec 10, 2009 12:01 pm

1. Why dont you use variables for this?
2. You could assign each enemy a unique ID ( For each enemy, set value "uniqueID" to LoopIndex) and have that unique ID correspond to a row on the array?

3. Or you could assign a unique ID to each enemy, then create an array object for each enemy and give the array a variable called "uniqueID" and make it the same as the enemies value.
---> Although actually, wouldn't it be better to just put an array a container with the enemy? That way each time a new enemy is created, a new array is also, and that array will be picked by default when the enemy is picked.

Just some suggestions, haven't tried them out so i may be wrong.
B
2
S
2
G
5
Posts: 448
Reputation: 2,546

Post » Thu Dec 10, 2009 12:06 pm

array container? go on... explain in more detail for me please. not sure what you mean here. sounds sort of like what im trying to do.

[quote:2izu7snt]1. Why dont you use variables for this?[/quote:2izu7snt]
why cant i use arrays? im unsure as to why there is no support for private arrays along side private variables. feels for of vital to me.

[quote:2izu7snt]2. You could assign each enemy a unique ID ( For each enemy, set value "uniqueID" to LoopIndex) and have that unique ID correspond to a row on the array?[/quote:2izu7snt]
i'd need to know how many enemies there is that way, to make sure the array has enough rows. enemies die and get created all the time.

[quote:2izu7snt]3. Or you could assign a unique ID to each enemy, then create an array object for each enemy and give the array a variable called "uniqueID" and make it the same as the enemies value.[/quote:2izu7snt]
same answer as 2# (i think..)
B
2
G
3
Posts: 12
Reputation: 874

Post » Thu Dec 10, 2009 12:17 pm

If you simply click your array in the objects panel at the side, then in the properties click "container". Then add the enemy object, this will mean that any new enemy will be created with a new container also.

As for sizes of array, you can just change the size with events if you need more, or just set the size as big as you need in the first place (do arrays enlarge themselves?)
B
2
S
2
G
5
Posts: 448
Reputation: 2,546

Post » Thu Dec 10, 2009 1:51 pm

Don't bother with looping/IDs. Just put the array in a container with the enemy and each enemy gets its own copy of an array. See Containers.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Dec 10, 2009 2:45 pm

What kind of values do you need to store and access. Because Private variables may be a better faster solutsion rather than an array. Or if you need dynamic variable addtions and subtractions look into using a hash table in the same way. They are much more organized and IMO easier to traverse because of the named keys.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests