PDA

View Full Version : Arrays of Arrays



Downloader
03-30-2018, 01:03 AM
I would really, really like to see some double array int variables.
Something like this:


//A variable int that is an array of several other arrays.
int ComboData[128][176];
//initialize all variables
for(int screen=0;screen<=127;screen++)
{
for(int comboposition=0;comboposition<=175;comboposition++)
{
ComboData[screen][comboposition];
}
}
void SaveMapComboData()
for(int screen=0;screen<=127;screen++)
{
for(int comboposition=0;comboposition<=175;comboposition++)
{
for(int x=0;x<=256;x+=16)//skips every 16 pixels
{
for(int y=0;y<=176;y+=16)//skips every 16 pixels
{
ComboData[screen][comboposition]=Game->GetComboData(Game->GetCurMap(),screen,comboposition);
}
}
}
}
//then afterwards
void WriteMapComboData()
for(int screen=0;screen<=127;screen++)
{
for(int comboposition=0;comboposition<=175;comboposition++)
{
for(int x=0;x<=256;x+=16)//skips every 16 pixels
{
for(int y=0;y<=176;y+=16)//skips every 16 pixels
{
ComboData[screen][comboposition]=Game->SetComboData(Game->GetCurMap(),screen,comboposition,ComboData[screen][comboposition]);
}
}
}
}

Chris Miller
03-30-2018, 10:54 AM
FTFY.

To answer your question about the Edit button, look toward the bottom-right of your post.

ZoriaRPG
03-30-2018, 06:25 PM
What you want, is '2D' array. It's not coming anytime soon, sorry.

I advise against using 'ComboData' as an identifier. That's a pointer, in the alphas of 2.54.

Other than those points, the for loops in your functions seem extraneous: +16 pixels isn't needed when you are using combo positions. In fact, your function calls are wrong, too, as you're calling a setter, but expecting a return.

Thankfully, the actual combodata datatype, and the mapdata datatype, make it much easier to do what it looks like you are trying to accomplish.

Downloader
03-31-2018, 02:59 AM
Calling a setter? That's not what happened.
I already compensated and shortened the script with a combo position for instead of writing a comboat(x,y) and shortened it into a 0-175 for instead.
Then I went and wrote out hundreds of lines of code to save the data and set it back at the push of a button in the same similar fashion as I wrote out in my example code for a hypothetical situation and got the results I was looking for which in no way "called a setter" but instead saved the combo data of every combo on an entire map by equating their values to a combo number on an array just as I described.
The only difference is that I had to manually write an array for every individual screen instead of an array that accesses other arrays as I had suggested for a future release.
I did this because the maps indices are limited to the point of 256 total maps, whereas writing all combo data to a series of arrays bypasses that limitation.
Also, I didn't call setters and expecting a return, those lines of code would in fact write to an array, not return anything.

ZoriaRPG
03-31-2018, 04:04 AM
Calling a setter? That's not what happened.
I already compensated and shortened the script with a combo position for instead of writing a comboat(x,y) and shortened it into a 0-175 for instead.
Then I went and wrote out hundreds of lines of code to save the data and set it back at the push of a button in the same similar fashion as I wrote out in my example code for a hypothetical situation and got the results I was looking for which in no way "called a setter" but instead saved the combo data of every combo on an entire map by equating their values to a combo number on an array just as I described.
The only difference is that I had to manually write an array for every individual screen instead of an array that accesses other arrays as I had suggested for a future release.
I did this because the maps indices are limited to the point of 256 total maps, whereas writing all combo data to a series of arrays bypasses that limitation.
Also, I didn't call setters and expecting a return, those lines of code would in fact write to an array, not return anything.

2.60 might support some form of shorthand format for invoking pseudo-2D arrays, but this will still use multiple arrays within the scope in which it is defined. This is a fatal flaw in ZC, as there are only 255 free global registers, and thus, every global array reduces the free registers for scripts, by one.

Grayswandir was working on syntax to allow it, but, at a global scope, woud need to be careful, and it is just a shorthand way of array index offsets.

The error in your code, is in this line:



ComboData[screen][comboposition]=Game->SetComboData(Game->GetCurMap(),screen,comboposition,ComboData[screen][comboposition]);


Note how you call SetComboData() in an assign here.

If you want to save stack space, define your combo arrays inside functions, per map. That way, you can populate one global array using a function with the combos from any virtual map, at any time.

The 2.54 ZScript spec allows direct access to mapdata and combodata:



combodata cur_map_combos[128*176]; //array size cap is 214748, so you could store four maps per array not including layers
mapdata m;
bool StoreScreenCombos(in map)
{
for ( int q = 0; q < 128; ++q )
{
m = Game->LoadMapData(map,q); //(map,screen)
combodata cd;
for ( int w = 0; w < 176; ++w )
{
cd = Game->LoadComboData(m->ComboD[w]); //Could also store as an int if you want. (All datatypes can now be global arrays.)
cur_map_combos[q*128+w] = cd;
}
}
return true;
}


...Something like that. I may increase the maximum map count, in which case, it will be possible to clone maps using mapdata, combodata, and other resources.

There is no logical way around the array size limit, though. It is a ZC maths cap, because all values are fixed-place at (val/10000), so the 32b system limit is the controlling factor. Thus, even with 2D arrays, you would not be able to have a 2D array with a total size greater than 214748 indices (in any combined format).

int myArr[107374][2] or similar, would be as large as you could go. This works for arr[256][256] and similar, but not for an array to hold that many variables in one place. :(

Downloader
03-31-2018, 04:43 PM
Sorry for my arrogance about saying I was right about what I wrote. It was just an example that I knew was fake so I wrote it up like array[][]=Set whatever on accident. In the meanwhile I was busy halfway through a script that actually works.
I realized the mistake I made and meant this:
//A variable int that is an array of several other arrays.
int ComboData[128][176];
//initialize all variables
for(int screen=0;screen<=127;screen++)
{
for(int comboposition=0;comboposition<=175;comboposition++)
{
ComboData[screen][comboposition];
}
}
void SaveMapComboData()
for(int screen=0;screen<=127;screen++)
{
for(int comboposition=0;comboposition<=175;comboposition++)
{
for(int x=0;x<=256;x+=16)//skips every 16 pixels
{
for(int y=0;y<=176;y+=16)//skips every 16 pixels
{
ComboData[screen][comboposition]=Game->GetComboData(Game->GetCurMap(),screen,comboposition);
}
}
}
}
//then afterwards
void WriteMapComboData()
for(int screen=0;screen<=127;screen++)
{
for(int comboposition=0;comboposition<=175;comboposition++)
{
for(int x=0;x<=256;x+=16)//skips every 16 pixels
{
for(int y=0;y<=176;y+=16)//skips every 16 pixels
{
Game->SetComboData(Game->GetCurMap(),screen,comboposition,ComboData[screen][comboposition]);
}
}
}
}

Anyway, I wrote a series of arrays for every screen on the map of size 176 integers a piece to achieve saving the state of the map and reloading it..

Here is an example video of what it would be used for, aside from a player option of Save/Load live in ZC, it would replenish combos that were used in my scrolling scripts, because essentially the code erases them off of the given map when picked up/sword slashed, and then the array calls put them back upon entering a different section of the map.
https://youtu.be/ulIZeH9ZxX0

Downloader
03-31-2018, 05:12 PM
So you're saying that an array the size of Array[10000] is possible? I believe that many years ago when I attempted something like that it was limited to much less than that.
Also, in my Dawn of Minora script I bypassed the size limit of the integers by wrapping into a new integer for place values by using the simple math function add(a,b) to have numbers writable up to trillions of place value.. I am sure a bypass like that would work for something like saving combo data also..

I have a question though about how many arrays are currently allowed in the first place.. I'm certain that 5-6 years ago it was limited to a lot less than I got away with this time, as ZQ would tell me that I ran out of integers pretty quickly, like around 100 variables or something, whereas this time I wrote several hundred and it works perfectly.

Downloader
03-31-2018, 05:13 PM
Also, I'm still looking for that edit button and it just isn't there..
Another thing, I wrote the staff here at AGN about password recovery and my loss of access to my old email address that I no longer have.. Is there any way I could get my old account activated again and reset the password. Old screen name "Zim."

ZoriaRPG
04-01-2018, 12:36 AM
Also, I'm still looking for that edit button and it just isn't there..
Another thing, I wrote the staff here at AGN about password recovery and my loss of access to my old email address that I no longer have.. Is there any way I could get my old account activated again and reset the password. Old screen name "Zim."

You might not be able to edit posts until your post count is > n, or you have been a member for n-days. Chris Miller might know about this one. I'm not sure.

The maximum size for a single array is 214748. The ZC system limits are often defined in std_constants.zh, particularly in 2.53.0b+.

Asuna Yuuki Nagato
01-19-2024, 10:39 PM
The maximum size for a single array is 214748.

Where did this magic number come from?

Gleeok
01-19-2024, 10:52 PM
Where did this magic number come from?

It's 100% magical like pixies and unicorns.

Step 1: take the number (2^31) -1
Step 2: ???
Step 3: profit.




*Note profit = dividing by 10,000. (it's a psuedo-fixed number hack that may or may not of been the best idea at the time (2006?).)