Defining array of arrays with data on multi lines
BlitzMax Forums/BlitzMax Beginners Area/Defining array of arrays with data on multi lines
| ||
Hi, I'm trying to initialize an array or arrays with data. The arrays are quite big so I'd like to do it on multiple lines, but when I compile I get the error "Compile Error: Expecting expression but encountered end-of-line" I'd like to have it on multiple lines to help visualise the data, it's very hard when it's on one line. Here is a simplified version of the code I'm using Type GameData Field Level:Int[][] Method InitLevel() Print "Init Level" Level = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] End Method End Type I've tried doing it like this: Level[0] = [1, 1, 1, 1] Level[1] = [1, 1, 1, 1] Level[2] = [1, 1, 1, 1] Level[3] = [1, 1, 1, 1] But get the error "Unhandled Exception:Attempt to index array element beyond array length" I would appreciate any help on initializing my array of arrays. I don't really want to use a 2D array because I'd like to enter my data like this. Also, so my data will work with languages that don't support 2D arrays. |
| ||
Don't know if it'll make a difference as I'm not big on arrays, but you can use .. to split long lines, i.e.:Type GameData Field Level:Int[][] Method InitLevel() Print "Init Level" Level = [[1, 1, 1, 1], .. [1, 1, 1, 1], .. [1, 1, 1, 1], .. [1, 1, 1, 1]] End Method End Type |
| ||
...Or...Level = Level[..4] Level[0] = [1, 1, 1, 1] Level[1] = [1, 1, 1, 1] Level[2] = [1, 1, 1, 1] Level[3] = [1, 1, 1, 1] |
| ||
Many thanks, both of you! I didn't know that .. lets you split long lines, good to know! Also, thanks for clearing up how to define the size of an array. |