Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Additional array commands?

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Oct 2013 19:48
Are there any plans for dynamic arrays? Or at least an array length command?

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Oct 2013 16:10
Really doesn't seem that way
I've been using the 0 element to store the size. It's ultimately more efficient than any array size command.
Inserting, deleting, sorting, etc have all had to be home brewed.
I have a feeling that since we can't pass arrays as arguments that it just won't ever happen.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Oct 2013 19:00 Edited at: 23rd Oct 2013 19:02
if you dim this array you know the count of entrys.
i had read with v2 (kickstarter) we get dynamic lists.
lbound(array)/ubound(array)/redim() like visual basic have i missing too.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Oct 2013 19:03 Edited at: 23rd Oct 2013 19:03
You're right! It's under stretch goal 2... I forgot about it completely!

Quote: "
Dynamic Lists
This data format will be added to the language.

Passing arrays to functions
The compiler will be improved to allow arrays to be passed to functions in your code.

Load & save arrays
Data arrays can be saved to local storage and re-loaded.

It is envisioned that the current Compiler will be re-written to accommodate these new data sets."


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Oct 2013 19:45
Quote: "I've been using the 0 element to store the size. "

I actually prefer starting my data at 0.

Right now, I'm using two global variables for my array. One keeps track of the physical size of the array, the other acts as a sort of internal pointer to how many elements I actually have stored. So for instance, I might have 10 items in my array, but it was defined with 15. This gives me room to grow without having to swap every time. Then, when I reach 15, copy the data to a temp array, redim with 20, copy back over.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Oct 2013 20:24
how do you redim?
it seems if i change the top index with dim again the old data stay in the "same" array. maybe you did not need to copy to temp for a new dim.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Oct 2013 20:38
I just use redim.
It now works OK on UDT arrays and single dimension arrays.
It does lose data with multidimensional arrays, so resizing needs to be done with the use of a temp array, which is ultimately safer (as long as you code well).

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Oct 2013 20:39 Edited at: 23rd Oct 2013 20:41
@Naphier
in beta 19 the compiler told me redim did not exist?
also without syntax highlighting.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Oct 2013 20:43
Oops sorry, my bad, just DIM

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2013 04:14
I use undim after copying to a temp array, then dim again.

Quote: "it seems if i change the top index with dim again the old data stay in the "same" array. maybe you did not need to copy to temp for a new dim."

Seems unsafe just from the way it might be allocating the memory in different places and not altogether.

Login to post a reply

Server time is: 2024-11-24 23:14:18
Your offset time is: 2024-11-24 23:14:18