slices broken
Monkey Forums/Monkey Programming/slices broken
| ||
the code below doesn't resize the arrays: [monkeycode] Strict Function Main:Int() Local a:String[]=["1","2","3"] a = a[..6] Print a.Length Local b:Int[] = [1,2,3,4] b = b[..8] Print b.Length Return True End Function [/monkeycode] |
| ||
Looks like this never worked (well I went back to v45c). You can slice to a smaller array or use Resize to increase the array. |
| ||
I did tried with resizing and it did work. |
| ||
I just found out also that Resize doesn't work if the array is 0 Length.Function Main:Int() Local a:String[] a.Resize(8) Print a.Length Return True End Function |
| ||
Hi, This is the way slices work in Monkey, you need to use Resize() to 'grow' an array. > I just found out also that Resize doesn't work if the array is 0 Length. Resize returns a new array, so you need to go: a=a.Resize(8) |
| ||
So in conclusion: * Use Resize when you want to change the size of an array * Use Slices when you want to get elements of an array Both of these operations return a new array and don't effect the one your are performing the operation on. |
| ||
Correct. If you want to do some more advanced stuff with arrays, check out the Arrays utility class in Diddy. |