How do I add the same array to multiple parent containers?

0 favourites
  • 7 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm using an array to store data attribs for different sprite troops. I can edit one of the troops, add the array to the container. That works fine. However, I select another troop sprite, try to add the attribs array again to this container and the array is not available to pick. Why not?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You simply can't have two containers with the same objects, that'd be impossible to accomplish. The only thing you could try is having all your "troops" in a single sprite object with multiples animations.

  • You simply can't have two containers with the same objects, that'd be impossible to accomplish. The only thing you could try is having all your "troops" in a single sprite object with multiples animations.

    Then how would each unique troop type have it's own unique array of attribs?

  • You can use one array and use one column for each unique troop. Or you can create a unique Array object for each troop.

  • You can use one array and use one column for each unique troop. Or you can create a unique Array object for each troop.

    So put every troop into one big sprite sheet with multiple animations, one fore each troop. The sprite sheet contains a 2 dimensional array holding data for each unique troop in the sheet.

    This could work. Probably the easiest way.

    Thanks guys

  • Question on the resource consumption using this giant-all-in-one sprite: Doesn't each instance of the different troop types created carry all the other data with it? Won't this be creating an enormous, bloated sprite for every instance?

  • I might have not understood properly, but I don't think you need an all-in-one sprite in the first place. It's less manageable, and no fun. I don't know what kinds of data you'd like to store, but in many cases, one array can hold the attributes for all your troops. For example, let's say you have Green, Yellow, and Red troops. Each troop has two attributes: Speed and Health.

    Define constants as follows:

    GREEN_INDEX = 0

    YELLOW_INDEX = 1

    RED_INDEX = 2

    ATTR_SPEED_INDEX = 0

    ATTR_HEALTH_INDEX = 1

    Now, make sure your array has a width of 3 (the number of troops), and a height of 2 (the number of attributes per troop). Now, you can set/store an attribute for a given troop by using the Array (Set at XY) command, where X is your troop index, Y is your attribute index, and Value is the value you'd like to set it to.

    For example, to set the Yellow troops health to 60, simply use Array (Set at XY): X = YELLOW_INDEX, Y = ATTR_HEALTH_INDEX, Value = 60.

    You can read these attributes in a similar way.

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