0 Favourites

3D Array of Variable Dimensions

  • With my project, I'm using a 3D array to store information about on screen levels.

    Each level holds a variable number of glyphs, but each glyph index holds 3 variables.

    So say I wanted the current UID of one of my glyphs using the array; I'd have it stored as:

    array[level][glyph][UID index]

    The way I have my code set up, there are a different number of glyphs to each level.

    Since the number of glyphs is random, I don't need an array height of the total number of glyphs, or one with extra spaces that are 0 and wasting space. I simply want to be able to insert a value at a specific XY, not just X or Y or Z.

    Is this possible with Construct 2? I already have the code integrated, so trying to find a way to do this is boggling my mind. :S

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • The dictionary object would be a better alternative. You definitely don't want to use a UID as an index, as the value can be anything, and you'd need to size the array arbitrarily large. Just merge your level, glyph, UID, and variable name together as a string to make the key. The same key will always get the data back again.

  • blackhornet thanks for the reply. I probably should have worded my post better: right now, I store the UID in the array I already have, along with two other variables. This is done after I create a new glyph object.

    The reason I store the UID is because I use it later to check the order of the glyphs, and to be able to remove specific glyphs based on user interaction, while manipulating other glyphs.

    I have the arrays really integrated, and this is why I want an array solution at the moment. I would rather worry about streamlining the process after I have a working version of the current system, since I came to a stop about half way in the process of converting my 2D array to a 3D one, rather than just beginning it.

  • You can't insert at an XY coordinate without pushing out the other dimensions. What you've described is essentially the Dictionary. I really wouldn't worry about wasting space just yet. Data is typically much smaller than your graphics/sound in a game anyway, as far as memory is concerned.

  • Darn. Well, thanks again for your input. I will check in to Dictionaries and see how they work.

  • Just like blackhornet said, a dictionary would be the better way for this requirement. On the other hand, let me take away a bit of your worries regarding wasted space:

    Assuming you only store numbers, each array cell consumes 4 bytes of RAM. With an array of 100x100x100 you need aprox. 3.8 MB of RAM

    This is exponential, of course, so the higher the total number of cells, the less likely it will fit to RAM. With 200x200x200 you're already at 30.5 MB. And with 1000x1000x1000 the RAM needed is 3.7 GB <img src="smileys/smiley3.gif" border="0" align="middle" />

    But if you stay somewhere under around 30,000,000 total cells, you're safe, because that's around 115 MB, an amount every smartphone can handle.

    (This only applies to numbers)

  • He could store those in the external files and load them on the go. Would that help?

  • tulamide thanks for clearing that up. :)

    Would either of you happen to have some good tutorials or examples using dictionaries? I've only had experience with vectors and arrays from my C++ classes, nothing quite like dictionaries.

  • Dictionaries are nothing to be frightened about. They are pretty simple. One dictionary can store any number of key/value pairs. A value is identified by its key.

    The advantage of a dictionary is that the key is a simple string, so you can use pretty much anything as key. Also, the value can be a string, so you could store hundreds of information under just one key. (For example a json string of an array under the key "myawesomearray")

    It is also valid to add keys with no value. This is useful to cache data.

    Examples regarding your project:

    • Using Level and Glyph as key for the UID value Add key "1,A" with value 102 You compose the key with str(level) & "," & [glyph] Later retrieving of individual parts of the key is done with tokenat()
    • You are not limited to one value. Add key "1,A" with value "102,someothervalue,justanotherone" Retrieving of individual elements of value is again done with tokenat()

    Pretty straight-forward.

  • Would you have any suggestions for finding, say, the length of a level within the dictionary? Depending on the length, each glyph will be updated individually by their UID and positioned sequentially, with each level of glyphs in a different place.

    I also check the previous and next glyphs and change those accordingly, when one is clicked. Though I don't think it'd be too difficult based on what you've posted.

  • Well , I'm with the others on using dictionnaries , I guess allocation 100x100x100 floats and not using them all would be a waste

    @megatronx , If every index would take 1 millisecond to load , that would be 100� milliseconds , around ... 10000 seconds ? I'm probably totally off , but that's ok , because you get the point xD

    Basically , you could add a string key to the dictionnary as "level|glyph1{0,1,1}|glyph2{0,1,1}|glyph3{0,1,1}" and compare the key with the level to load , then get the desired glyph using tokenat(src, index, separator)... basically , store all the info in one big string

  • To avoid array-like dictionary keys, I'm current using a template like:

    LevelXGlyphYVariableZ

    Where X Y and Z are whatever values I need them to be. Honestly I'm not too keen on using the tokenat unless I have to.

    Each time a new glyphs is created, which is one at a time, I store three new keys, which are basically variations of, for example, Level2Glyph0VariableX, Level2Glyph0VariableY, Level2Glyph0VariableZ.

    To see if a glyph exists in the dictionary, I simply check if the key Level1Glyph5Variable0 exists.

    However, counting glyphs will be a pain unless, so I think when I "destroy" a glyphs, I will count the UID as zero, and while counting or going through the "list" of glyphs, ignore anything with a UID of 0. :)

    Again, thanks everyone for your input. I'm slowly getting my system converted to use a dictionary instead of an array.

    I can't wait to put my game together. In two weeks time I will be showing my Game Design club what I've finished! :D C2 has taught me much about using arrays, dictionaries, angular interpolation, and keeping my code tidy. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
1,941 263,182
FlyingRam's avatar
FlyingRam
Unread hot topic
0 Favourites
[Plugin] Three.js 3D canvas
134 12,718
Schoening's avatar
Schoening
Unread hot topic
82 7,339
Ashley's avatar
Ashley Construct Team Founder