Dynamic array sizes?
-
Is it possible to create arrays of dynamic sizes (such as expanding/truncating the size of an existing array, basically treating it as a collection)? If so, how?
-
You can do the following
myarray = [] myarray[1] = 1 myarray[2] = 2 myarray[3] = 3 .... myarray[100] = 100
-
@MikeDX Thanks, but I get a hard crash when I try that with nested struct arrays. I can't reproduce the crash in a smaller example, but I get a strange error ("Unrecognized type error") in the following example. It might be the same issue that produces the hard crash in the larger program.
struct struct1 int i = 1 endstruct struct ownerstruct struct1 s = [] endstruct ownerstruct os[10] struct1 mys mys.i = 2 os[5].s[4] = mys loop clear print(os[5].s[4].i) update() repeat
If I change the
struct1 s = []
into a fixed array, it works:
struct1 s[10]
-
What if you assigned it to os[5].s[0]?
-
@Discostew said in Dynamic array sizes?:
What if you assigned it to os[5].s[0]?
That works!
(Still doesn't solve the hard crash in my larger program though.) -
@Nisse5 said in Dynamic array sizes?:
@Discostew said in Dynamic array sizes?:
What if you assigned it to os[5].s[0]?
That works!
(Still doesn't solve the hard crash in my larger program though.)Methinks that to make it dynamic, it needs to grow from the lowest to the highest without jumping over any steps. Before the step where you call os[5].s[4] = mys, what happens if you call the previous ones like this - "os[5].s[y] = []", where "y" is index 0, 1, 2, and 3 (like in a FOR loop)?
-
There seems to be something wrong with arrays that causes type errors under heavier usage, will make another bug post about it shortly