assign array to object

This forum is currently in read-only mode.
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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?

    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?

    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.

    same answer as 2# (i think..)

  • 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?)

  • 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.

  • 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.

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