How to init array?

About Monkey 2 Forums Monkey 2 Programming Help How to init array?

This topic contains 12 replies, has 9 voices, and was last updated by  Danilo 2 years, 1 month ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #6335

    Diffrenzy
    Keymaster

    Can’t seem to nail this, so what is the MX2 equivalent of :

    Local score:Int[]=[10,20,30]

    #6336

    scurty
    Participant
    #6337

    Diffrenzy
    Keymaster

    Thanks scurty! Is it documented somewhere?

    #6342

    nerobot
    Participant

    Somewhere on the forum is.. 🙂

    #6347

    codifies
    Participant

    … if only there was a wiki for all this stuff…

    #6361

    Mark Sibly
    Keymaster

    … if only there was a wiki for all this stuff…

    This is fundamental stuff that *should* be in the language reference, not a wiki.

    It’s my fault it isn’t of course, and I’ll be spending some time soon updating the docs.

    #7321

    Xaron
    Participant

    So how can I init a 2d array?

    edit: Found the solution: http://monkey2.monkey-x.com/forums/topic/way-to-predefineinline-define-an-array-of-arrays/

    #7326

    AdamStrange
    Participant

    field _tracks:Track[, ] = New Track[64, 8]

    tried to do the fill using different methods, but none worked. best solution would be to use data and read it into the array?

    #7329

    Danilo
    Participant

    @xaron:
    Maybe you could use array-of-arrays for this case?

    #7330

    Mark Sibly
    Keymaster

    There’s currently no way to init 2d arrays like this sorry. You’ll need to use an array of arrays, ala Danilo suggestion, or manually initalize elements one by one.

    I do plan to add this eventually (and N-d copies, slices etc) but it’s a little tricky due to c++-isms, and with 3d, 4d arrays etc the syntax gets pretty weird.

    #7342

    nobuyuki
    Participant

    yay slices.  Best of luck

    #7343

    Xaron
    Participant

    Thanks guys! 🙂

    #7345

    Danilo
    Participant

    Another way for initializing an array-of-arrays, provided by Mark himself:

    Good example for the MX2-CODE-COLLECTION. 😉

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

You must be logged in to reply to this topic.