Does zscript fully support multidimensional arrays?
If I write `int foo[32][16]` and then `foo[17][14] = 123`, I'll get an index out of bounds error.
If I write `int foo[32][16]` and then `foo[15][14] = 123`, I get no error.
In other words it looks like indices for every dimension have to fit within the smallest dimension size, if that makes sense. Either I'm doing something horribly wrong here or there's a nasty bug.
zscript multidimensional arrays?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Re: zscript multidimensional arrays?
Huh, so it's backwards?
So just to be clear, if an array were defined in ACS as `int foo[10][20][30]`, then in zscript it should be defined as `int foo[30][20][10]`, right? But when indexing the array, as in `bar = foo[1][2][3]`, it would be the same in both ACS in zscript?
So just to be clear, if an array were defined in ACS as `int foo[10][20][30]`, then in zscript it should be defined as `int foo[30][20][10]`, right? But when indexing the array, as in `bar = foo[1][2][3]`, it would be the same in both ACS in zscript?
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: zscript multidimensional arrays?
It's a bug, but unfortunately one buried deep in the parser logic so it's not easily fixable.
Re: zscript multidimensional arrays?
Got it, thanks 
For anyone else who happens to find this, it does work the way I described in the previous comment... declaration is reversed from ACS, but indexing is the same. The other thing to watch out for is ACS array access is more robust, allowing you to index arrays with out-of-bounds indices (evals to 0), while zscript will not allow this. So you might need some extra guards around your array access in zscript, when porting stuff from ACS.
For anyone else who happens to find this, it does work the way I described in the previous comment... declaration is reversed from ACS, but indexing is the same. The other thing to watch out for is ACS array access is more robust, allowing you to index arrays with out-of-bounds indices (evals to 0), while zscript will not allow this. So you might need some extra guards around your array access in zscript, when porting stuff from ACS.
Re: zscript multidimensional arrays?
Could this be fixed with versioning? or is that completely impossible and I'm an idiot?
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: zscript multidimensional arrays?
The problem is not versioning, it's how the compiler frontend constructs types out of the source code. The code is rather badly designed but changing it would risk breaking stuff way beyond the order of array indices.
