untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 14 forks source link

Help with arrays: How to add an item? #84

Closed SodaPopinski closed 5 months ago

SodaPopinski commented 1 year ago

I can't figure out how to add an item to an already existing array. I've tried my_array.add(item), my_array.Add(item), my_array.append(item). I always got an error that the array doesn't have that method.

I've also tried creating a second array with the item, and tried adding the two arrays together, and got an error that int[] can't be added to int[].

Am I missing something, or is this function not implemented?

untoldwind commented 1 year ago

Yes this is kind of missing.

The reason why I was somewhat careful about this in the beginning was that a const array should be indeed const i.e. readonly. So something like array.add_time should only be possible for non-const arrays. ... and then I forgot about it ;)

I will extend the API/language like this:

array1 + array2    // Always creates a new, concatenated array (array1, array2 remains unchanged)
array1 + element // Always creates a new array with an additional element (array1 remains unchanged)
array1 += array
array1 += element // Both only possible if array is non-const (i.e. `let` or in a Cell)
untoldwind commented 1 year ago

This should work now in 0.3.5 or 0.4.0.1

untoldwind commented 5 months ago

Closing this for now. Just reopen if the problem pops up again