Creating an Array
Monkey Forums/Monkey Programming/Creating an Array
| ||
I want to create an array of arrays, and I'm initializing like this:gameGrids = [ [ [ [1],[2] ], [ [3],[4] ] ] ] but it's giving me a syntax error on line 2, "Expected ']'" That expected bracket is on line 3. Is that really illegal? Is the opening bracket on line 1 illegal? Ultimately, I'd like to do something like this: gameGrids = [ [ [ [1],[2] ], [ [3],[4] ] ], [ [ [2],[1] ], [ [3],[4] ] ], [ [ [1],[2] ], [ [4],[3] ] ], [ [ [2],[1] ], [ [4],[3] ] ] ] so that I have 4 different grids in the set, and I can choose the current one with currGrid = gameGrids[X]. This is just an example. My grids ultimately will get to up to 3 rows and 3 columns. The point here is, can the opening and/or closing brackets be on separate lines as shown above? |
| ||
You can end a line with a comma or an opening bracket but not a nested closing bracket which is a pity in regards to formatting, perhaps Mark could look into a "fix". |
| ||
Thanks for the info, skid. Is that somewhere in the docs? I'd like to get more familiar with finding my own answers so I don't have to clutter up the forum. :) |
| ||
Or, if semicolons were mandatory, you could end a line with whatever you wanted. :) |
| ||
True, but languages like Python manage to handle this sort of formatting without them. |
| ||
True, but languages like Python manage to handle this sort of formatting without them. If you like using whitespace for your syntax, sure. This is the granddaddy of Python: http://en.wikipedia.org/wiki/Whitespace_%28programming_language%29 |
| ||
Whether or not I like Python's significant whitespace isn't the point. The point is that it doesn't need a semicolon to denote the end of a statement to allow you to format an array definition across several lines and with indents of your choice. The array brackets delimit the definition quite adequately. |