Array strangeness
Monkey Forums/Monkey Programming/Array strangeness
| ||
I'm confused by this.. There is nothing in the docs that would explain why this bombs out. This works.. Function Test:Void(num:Int) Local c:Int = num Local ap:Float[] ap = New Float[c] End This fails... Function Test2:Void(num:Int) Local c:Int = num Local ap:Float[][] ap = New Float[c][3] End |
| ||
I don't think multidimensional arrays are possible. |
| ||
I think you need to make a class for the data type, and then use that as array element. |
| ||
No multidimensional arrays in Monkey. |
| ||
WTF? Why would there be no multi dim arrays? All the target languages support them. The Monkey docs show examples of multi dim arrays. I find it hard to believe that mark would cripple the language that way. |
| ||
Well Mark wrote in his blog: http://marksibly.blogspot.com/2010/08/self-compiling.html * Multidimensional arrays are out, although you can still have arrays of arrays, eg: Local t[10,20] 'OK in bmx1, Error in bmx2 Local t[][10] 'OK in bmx1 and bmx2. * Arrays can not be 'downcast' in bmx2, eg: Local t:Object[]=New Thing[10] Local p:Thing[]=Thing[]( t ) 'OK in bmx1, Error in bmx2. This will mean that arrays may have to be manually 'wrapped' in some situations. |
| ||
Xaron, whats the point of your post? I've never tried to use bmax style arrays. Look at my examples again. I'm using the C style declaration, which is compatible with the docs and Marks blog posts. |
| ||
Looking at your failed example you obviously did not. ;) So your creation of a two-dimensional array fails because it is simply not supported that way. That is what Mark writes in his example as well. No offense here, sorry if I was a bit rude. |
| ||
congrats! your the monkey forums first troll. I hope Mark can clear up this array business. |
| ||
Could you elaborate why? Maybe I just missed your point... |
| ||
What do you think you are doing here? New Float[c][3] |
| ||
because the array is declared with [][] not [,]. That's compatable with the docs and marks blog post. Nowhere is it stated that arrays with 2 dimensions "[][]" are not supported. Thats a pretty huge deal, I think it would have come up.. |
| ||
This works:Import mojo Class ArrayExample Extends App Method OnCreate() SetUpdateRate 30 Local blah:Int[2][] Local arr1:Int[4] arr1 = [0,1,2,3] Local arr2:Int[4] For Local f:=0 To 3 arr2[f] = (f+1)*10 End blah[0] = arr1 blah[1] = arr2 For Local f:= 0 To 1 For Local f2:=0 To 3 Print blah[f][f2] Next Next End Method OnUpdate() End Method OnRender() Cls 50,50,50 End End Function Main() New ArrayExample End |
| ||
For the record I think these are called jagged arrays. |
| ||
Thanks Beaker, very interesting! @_GW: Sorry it was not my intention to troll. :( I guess I simply misunderstood something here... |
| ||
You werent trolling, m8. |