Creating new arrays

About Monkey 2 Forums Monkey 2 Programming Help Creating new arrays

Tagged: 

This topic contains 8 replies, has 5 voices, and was last updated by  degac 2 years, 7 months ago.

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

    Ethernaut
    Participant

    Ok, really basic. How do you create a new array and add all values at once (without iterating)?

    In Monkey1 it used to be:

    In Monkey2 that doesn’t work. I also tried this:

    Doesn’t work either.

    Help!

    #833

    degac
    Participant

    +1

    I really love (in Bmax) this

    I don’t know if MX2CC can ‘understand’ this type of situation or needs a ‘creation step’ before (I mean how many items can the array store initially).

    At least something to ‘feed’ the array in some way could be handy

     

    No matter, I found the solution on the MonkeyX forum (referring at a blog post here :D)!

     

    In any case I found that this works

    So Int[] and String[] can be ‘instanced & resized’ automatically depending on the items passed

    This one doesn’t work (

    I need to specify the size of the array

    Maybe (probably!) I missed something obvious in the syntax.

     

    #834

    Ethernaut
    Participant

    This works:

    I think String.Split() already returns a new array, so you don’t have to use “New” or specify the size before calling it!

    And yes, I posted in the Monkey-X forums as well, but I like posting here since it can be useful to people starting on Monkey 2.

    Cheers!

    #837

    degac
    Participant

    I think String.Split() already returns a new array, so you don’t have to use “New” or specify the size before calling it!

    Thanks – I know I’ve did something wrong in the syntax!

     

    I think I’ll add these informations directly in the modules section/monkey-types/array http://monkey2.monkey-x.com/modules-reference/

     

    #1274

    Simon Armstrong
    Participant

    I missed this one before:

    Found it again here

    #3509

    degac
    Participant

    OK, after trying & searching I need help.

    How we can ‘resize’ an array?

    #3510

    Jesse
    Participant

    > Method Slice:T[](from)
    or
    > Method Slice:T[](from:Int,term:Int)

    I think you need to do a CopyTo:
    > Method CopyTo:Void( dstArray:T[], srcOffset:Int, dstOffset:Int, count:Int )

    I believe you have to create a temporary variable array of the desired length as I don’t see any other way.

    or you can simply resize an empty array:
    > nn = New Float[10]

    #3512

    Mark Sibly
    Keymaster

    Slice() can shrink an array but it can’t grow it – I still need to add a proper Resize().

    #3521

    degac
    Participant

    OK, thanks

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

You must be logged in to reply to this topic.