3D Array of Variable Dimensions

Get help using Construct 2

Post » Tue Nov 19, 2013 11:05 pm

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. :SDatapawWolf2013-11-19 23:06:47
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Post » Tue Nov 19, 2013 11:43 pm

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.
ImageImageImage
B
71
S
21
G
222
Posts: 3,652
Reputation: 124,733

Post » Wed Nov 20, 2013 12:50 am

@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.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Post » Wed Nov 20, 2013 1:04 am

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.
ImageImageImage
B
71
S
21
G
222
Posts: 3,652
Reputation: 124,733

Post » Wed Nov 20, 2013 1:10 am

Darn. Well, thanks again for your input. I will check in to Dictionaries and see how they work.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Post » Wed Nov 20, 2013 1:33 am

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
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)
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Wed Nov 20, 2013 1:40 am

He could store those in the external files and load them on the go. Would that help?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
86
S
28
G
21
Posts: 1,981
Reputation: 19,316

Post » Wed Nov 20, 2013 1:40 am

@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.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Post » Wed Nov 20, 2013 2:06 am

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.tulamide2013-11-20 02:06:34
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Wed Nov 20, 2013 2:19 am

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.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest