Way to predefine/inline define an array of arrays?

About Monkey 2 Forums Monkey 2 Programming Help Way to predefine/inline define an array of arrays?

This topic contains 8 replies, has 6 voices, and was last updated by  Mark Sibly 2 years, 1 month ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #7297

    Jesse
    Participant

    is there a way to define an array of arrays? something like in monkey1.
    I tried this but it doesn’t work:

    Global data:String[][] = New String[][]([“cat”,”dog”],[“monkey”,”parrot”])

    #7299

    abakobo
    Participant

    you can have multidimensional arrays Myarr[x,x] or arrays of arrays Myarr[][] depending on what you need.
    multidimensional arrays are much simpler.
    you can directly initialize simple arrays only.

    simple and multidimentionnal arrays are explained in the latest docs (in github) but the arrays of arrays are not explained (see link)
    http://monkey2.monkey-x.com/forums/topic/syntax-for-array-of-arrays-jagged-array/

    an example of multidimentionnal array:

    [/crayon]
    #7300

    Jesse
    Participant

    I know how to fill it one item at a time. I just don’t know how how to or if there is a way to do it in a single instruction.

    #7304

    abakobo
    Participant

    you can only predefine simple arrays so it will take two lines with your array of array example([][]). With a multidimensional([,]) array it’s not possible at all for now.

    this is the most you can have for now i think..

    [/crayon]
    #7307

    Jesse
    Participant

    That’s exactly what I didn’t want to do. I guess I’ll have to settle for that.
    Thanks.

    #7310

    nerobot
    Participant

    New String[][]([“cat”,”dog”],[“monkey”,”parrot”])

    AFAIK there is no such syntax, and I would like to have it too.

    #7322

    Xaron
    Participant

    I second that. 🙂

    BTW: I’ve seen that there are two kinds of multidimensional arrays?

    Why is that?

    #7328

    Danilo
    Participant

    @xaron
    New Int[10,10] is a multi-dimensional 10×10 array.

    New Int[][10] is an array of arrays, and each array can be different in size:

    #7333

    Mark Sibly
    Keymaster

    This works…

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.