2D Arrays

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by  degac 3 years ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #819

    Ethernaut
    Participant

    Hi!
    This code:

    Works relatively unchanged in Monkey 1, but I can’t get it to work in Monkey 2. It seems it doesn’t like the “Local temp:String[x][]” line.

    How do you create a 2D array in Monkey?
    Something that can be accessed like myArray[x][y], or similar to that?

    Thanks!

    #824

    degac
    Participant

    Hi

    In MX2 2D arrays are like in Bmax, just define them with New String[w,h] (or New Int…etc)

     

     

    OT:

    Just a side note, the ‘crayon’ highlighter should allow to setup a ‘default’ language when you type in the code-box section… I just noticed you need to select it manually (I’m sure there’s an option for the crayon-module somewhere)

    #825

    Ethernaut
    Participant

    Ooooohh, awesome!

    Much better than creating a new function for every type of 2D array you need, like you have to do in Monkey1.

    Thanks!

    #826

    GW
    Participant

    2d arrays are very much *not* like Bmax

     

    local ta:String[2,2]  <– error

     

    #827

    Ethernaut
    Participant

    I think you just need to create a new array object. This works:

    local ta:= New String[2,2]

    Cheers.

    #828

    degac
    Participant

    Well, I mean the syntax and the ‘accessing method’ (index separated with commas) is very similar to Bmax.

    Just the definition is different. Maybe it’s a needed step for wider compatibility with the target languages.

    I prefer this 2D array than the ‘standard C’ version [][]

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

You must be logged in to reply to this topic.