Help with weird arrays issue

Hey.
So this is a general algorithm question. I don’t need the code, I just need the idea of how to do it.

So I have a 2D array, and I am storing values in it. It’s a bit weird, so bear with me here:
I have some variables, that take a single cell. That is a standard array value.
I have other variables, that take 2 cells. I can’t store the same variable in 2 cells, because that would mean two single cell variables, and I want a single variable that is stored in 2 cells.
Then I have even larger 4 cell variables. Again, I can’t store this variable in all 4 cells, cause then all the other algorithms will read it as four single cell values, and I don’t want that.

The best way I can explain what I want to do is something like this:


Imagine each square as an array cell and each item is a variable, that takes different amount of space in that array.

Any ideas would be greatly appreciated. Thank you :blush:

  • Represent Item with a symbol
  • store the symbol ↔ Item relation in a seperate array
  • store the symbols (or group of symbols) in the array the represents the inventory
2 Likes

or an ID value

elaborate please

I still can’t save 4 ID values in 4 different cells, cause when I use a for loop for something I will end up with 4 different objects instead of 1 object…

You save what is in which cells. You never process the visible data, just the data-data :slight_smile:

1 Like

I am not sure I understand…
So you are telling me to build another array that will store the variables and their location in the main array.
But when I go to the main array and try to visualise the other array I bump into the same issue…

To use my example as an example, a dagger is stored into A1 and A2, but when I try to visualise I read A1 - dagger, A2 - dagger. So I end up with 2 daggers…

I am not making an inventory by the way, but that is the best visualization of what I want to do…

The two arrays you want me to make are basically the same, just stored in a different way…
I can’t wrap my head around it.

No. I am telling you your “main array” (visible inventory) is not the main array.

You used the wrong array then. In the data-array, the dagger is in slot 1 (technically 0). Slot one contains the info that the dagger is in A1 and A2.

1 Like

Oh… Ooohhhh… I see what you mean now…
I can add extra cells to the main main array for extra info to help me with the visual array that I will use only for visualisation…

OK, that IS an idea I can try and use. OK, I will spend some time trying to implement that and will be back in a couple days with an update eventually maybe.

Any other ideas would also be appreciated.

1 Like