Posted: 27th Feb 2023 13:37
Can we make it so Thing.insert(me, index) is smart enough to add a new index if index is length+1?

For example, so we don't have to do this:
+ Code Snippet
IF iInsert+1 <= Thing.length
    Thing.insert(InsertMe, iInsert+1)
ELSE
    Thing.insert(InsertMe) // Insert New, at end of array.
ENDIF


Heck, we could go a step further and have it extend the array as far as needed for the insert.
Example:
+ Code Snippet
Thing AS INTEGER[5]
//  [ 0, 0, 0, 0, 0, 0 ]

Thing.insert(33, 9)

//  Thing.length now = 9
//  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 33 ]
Posted: 27th Feb 2023 17:18
AGK already does that.
Posted: 27th Feb 2023 17:21
If you have 10 things in an array the length will show as 9 with 0 being the first. An empty array has a length of -1 (minus one)
Posted: 27th Feb 2023 17:44
AGK already does that.

i think you missed the point. when using the index parameter:
+ Code Snippet
myArray as integer[4] 
myArray[0] = 10
myArray[1] = 11
myArray[2] = 12
myArray[3] = 13
myArray[4] = 14
myArray.insert(15,6) 

...will crash while i believe Nieb would like AppGameKit to automatically check if the current length of the array can accomodate the specified insert location. if not, automatically resize so that it can.

@nieb, i can see the value in what you're looking for. any feature request you might post would fit nicely in future array-related updates. in the meantime, we can write our own work-around realitvely easily, at least
Posted: 27th Feb 2023 18:59
You could just say Thing.length = 9
Posted: 27th Feb 2023 21:42
@Virtual Nomad:
I had a feeling I was missing something, I didn't fully understand the question.
Posted: 27th Feb 2023 21:44
I personally prefer to use Thing.length = 5 rather than Thing AS INTEGER[5] That's probably why I didn't fully understand.