September 9, 2016 at 8:06 am #3816
What is the syntax for declaring this? (Not multidimentional arrays)
Since the below code compiles, I assume Arrays of Arrays are still in , but I can’t seem to get the declaration syntax right. Local jag:Float = New ????
Local arrlist:= New List<Float>
Local multi:= multi.ToArray()
End functionSeptember 9, 2016 at 8:55 am #3819
Quick demo:Monkey12345678910111213141516171819Function Main()Local w:=20,h:=10Local t:=New Int[w]For Local x:=0 Until wt[x]=New Int[h]NextFor Local y:=0 Until hFor Local x:=0 Until wPrint t[x][y]NextNextEnd
Note that the ‘new’ is sort of back to front, ie: in the ‘New Int[w]’ bit, w comes last, but when you’re indexing with ‘x’ it comes first!
This actually makes sense to me as a compiler coder, ie: ‘New Int[w]’ is w new int arrays, which is what we want, but I think java/c# parse things kind of differently so you end up with ‘New Int[w]’ instead, which or may not make more sense to others.
I’m pretty relaxed about changing this if enough people prefer the Java way.September 9, 2016 at 9:03 am #3820
Hi Mark, thanks for clearing it up, I don’t think I would have figured that out 🙂
I’m all for changing it to the java/monkey1/c# for consistency between languages.
Also, it seems logical, that the major dimension, that holds the elements are declared first.September 9, 2016 at 9:11 am #3822
deleted.January 22, 2017 at 6:37 pm #6738
errr wot!Monkey123456789101112[crayon-5d094d145cf49456056228 inline="true" ]Global a:Int = New Intglobal b:Int'Global c:Int = New Int'Global d:Int = New IntInt'Global e:Int = New Int New IntFunction Main()End Function
if b works why the heck doesn’t c (like a few other languages) – do I really need a loop just to make an empty array?January 22, 2017 at 7:50 pm #6740
If you want some ‘rectangular array’ you can do the following:Monkey1234[crayon-5d094d145e6c9652273754 inline="true" ]Local map1:= new int[10,10]Local map2:= new int[7,9]
orMonkey1234567[crayon-5d094d145e6ce349367312 inline="true" ]Local map1:int[,]Local map2:Int[,]map1= new int[10,10]map2= new int[7,9]
If you want an array of various arrays (non-rectangular/jagged) you’ll have to loop as mark showed. h could have different values during the loop.January 22, 2017 at 11:39 pm #6741
…ah jee that should be in the docs!
You must be logged in to reply to this topic.