for behavior
Community Forums/Monkey Talk/for behavior
| ||
Why can i not do this? For z:int=0 to blocksZ-1 (syntax error) |
| ||
int must be written Int, and to must be To, and you need also a Next or End, and if your z was not declared earlier, you need also Local, so it should look like: For Local z:Int=0 To blocksz-1 Next] Last edited 2011 |
| ||
thx i got a next it must be the int and Local bit It is a bit verbose isnt it :/ Last edited 2011 |
| ||
Another 'victory' for case sensitivity :P~ |
| ||
I like case sensitivity, well, at least where variables/identifiers are concerned. I dont care about keywords & default types. It was not the small case int, it appears either works there, it was the lack of that local keyword. while we are at it this is wierd too: const blocksX:int = 100 const blocksY:int = 10 const blocksZ:int = 100 const DefaultTop:int = 1 Field blocks:Block[][][] Method New() blocks = new Block[blocksX][blocksY][blocksZ] the last line is giving : Error : Only strings and arrays may be indexed. um... eh? Last edited 2011 Last edited 2011 |
| ||
Unfortunately Monkey doesn't let you allocate multi dimensional arrays like that. You will need to allocate the first dimension (an array of 2D arrays) then loop through each entry allocating the next dimension (an array of 1D arrays), in that looping through each of those (so they themselves point to a new Array). http://www.monkeycoder.co.nz/Community/post.php?topic=234&post=1889 Last edited 2011 |
| ||
Argh that is horrible news. although in the manual (language ref) it does show an declaration of something:int[][] it just does not tell you how to initialise it. |
| ||
You do know you can write: For Local z:=0 Until blocksz ? |
| ||
nope but now i do :) |
| ||
I gave up in the end trying to make a 3 way multi dim structure initialize... it gave me a headache. In the end i came up with: Class World const blocksX:int = 100 const blocksY:int = 100 const blocksZ:int = 10 const DefaultTop = 1 field blocks:Block[] method New() 'Init blocks blocks = new Block[blocksX*blocksY*blocksZ] for local z:int = 0 until blocksZ for local y:int = 0 until blocksY for local x:int = 0 until blocksX blocks[GetBlockIndex(x,y,z)] = new Block next next next end method GetBlockIndex:int (x:int, y:int, z:int) return x + (y*blocksX) + (z*(blocksX*blocksY)) end method GetBlock:Block(x:int, y:int, z:int) return blocks[x + (y*blocksX) + (z*(blocksX*blocksY))] end end class Block field WallLeft:int =0 field WallRight:int =0 field WallTop:int =0 Method New() end end yay oldskool. It will do... i suppose :P Last edited 2011 |
| ||
Oh thanks, this is handy! |