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 / wanted: dynamic arrays in types

Author
Message
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 21st Jan 2011 14:02
We want arrays, particularly dynamic arrays, in types!!

Who's with me?

[center]
Join the TGC Group!
http://tehcodez.groups.live.com
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Jan 2011 14:10
I'm with you! Yes+1

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Jan 2011 14:21
Definitely, it's practically essential really.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 21st Jan 2011 15:41
Yes.

Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Jan 2011 16:10
Yes

[b]
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jan 2011 16:46
Yes.
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 21st Jan 2011 17:08
DMXtra
21
Years of Service
User Offline
Joined: 28th Aug 2002
Location: United States
Posted: 22nd Jan 2011 08:36
Yes definitely. Number one (Lee) make it happen.

Dark Basic Pro - The Bedroom Coder's Language of choice for the 21st Century.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Jan 2011 12:47
Arrays in UDT's, and arrays in arrays, and (though some may disagree), arrays need to be held as references that can be assigned/moved if needed.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Jan 2011 19:46
Dynamic arrays in UDTs could improve so many of my codes! Or make them easier to write at least.

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 17th Feb 2011 16:42
Yes. UDT Arrays are essential.
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 18th Mar 2011 04:22 Edited at: 18th Mar 2011 04:22
So you are looking for something like this:

TYPE fredtype
x AS FLOAT
DIM y[100,500] AS FLOAT
z AS FLOAT
ENDTYPE
TYPE leetype
a AS INTEGER
DIM b[100] AS fredtype
ENDTYPE
DIM lee[100] AS leetype
lee[50].b[10].y[33,250]=42.42

I can do this, but the arrays would not be dynamic and could only be assigned literal absolute values for the sizes. The reason is that UDT data types are treated like value blocks in the compiler. Given this, each instance of the UDT would be the size of the entire array and it's members.

I am hesitant to add this to AppGameKit as it will perhaps promote the creation of apps which gobble very large chunks of initial memory from the device. At least with dynamic arrays you can grow them as you need them. Another downside to statically defined arrays is that you tend to fall off the end all too soon, as the arrays are often created quickly and then forgotten about.

Another reservation I have is that traditionally we have used DIM as a way to dynamically create and resize arrays at will, now we find it inside a TYPE declaration but it cannot be dynamically sized and it's not even a command as such, but a pre-declaration of a UDT structure. Is it not better to keep the UDT a simple creature, and promote the user of the dynamic array with the UDT structure a natural child element of an array.

Remember, if you need an array within a type, you can always switch around the declaration, i.e:

Dim lee[50] As leetype
lee[42].a=1
lee[42].subarray[10]=1

Almost identical lines with the same result would be:

Dim lee[50] As leetype
Dim leesubarray[50] As leesubarraytype
lee[42].a=1
leesubarray[42,10]=1

All that said, I could also radically amend the UDT system to allow dynamic arrays within types (and by virtue arrays within arrays) but it would be a considerable undertaking which would certainly delay the release of AGK. The work involves ensuring that every part of the system that is exposed to a UDT can handle the idea of a nested array pointer in there somewhere, which has implications when you consider things like UDT values passed into user functions and copying UDT variables from one to the other. Not to mention a TYPE is declared once, so having a command like DIM subarray[myvar] AS INTEGER could not work unless myvar was a constant. You would have to have a new approach to dynamic array creation inside a UDT such as:

myvar=10 : DIM lee[42].subarray[myvar] AS INTEGER

As you can see it can get messy! It seems from the thread so far your vote would be yes, and the verdict would be that this is an 'essential' feature, but would you be willing to wait another 6-8 weeks while I tear up the old UDT system? This is the real question for you guys! P.S. I don't want to re-create 'C' For 'C', see Tier 2!

I drink tea, and in my spare time I write software.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 18th Mar 2011 09:26
Lee:
I would say nice to have but not needed. I have used your method of multiple arrays before. And I much rather don't wait longer for AGK. So my vote would be:

LATER

DMXtra
21
Years of Service
User Offline
Joined: 28th Aug 2002
Location: United States
Posted: 18th Mar 2011 11:18
I vote later on this. This is needed, but not worth the delay it would take to AGK.

Lee, I would mark this on your todo list though, just not needed at launch.

Dark Basic Pro - The Bedroom Coder's Language of choice for the 21st Century.
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 19th Mar 2011 14:45 Edited at: 19th Mar 2011 15:13
I personally feel static and dynamic arrays in types are both essential. I would be willing to wait 8 weeks. I would be willing to live with a normal release and then 8 weeks later get an update with dynamic types in UDTs.

Here's a story about how I'm using it:

I'm working on a GUI in a different language. The language supports dynamic arrays in types.

My code looks like this. Sorry for the line numbers:


so to add a window, I call a function that adds an item to my odd_windows dynamic array (list in this language's case). From there, I add widgets to the window. There is a bit of waste there, mostly by using strings the way I am (there's other reasons that don't really need delving into in this thread), though there is waste in linking UDTs. However, the structure in my mind is so much simpler than it would otherwise be.

In a typical running, the overall structure looks like this



As you can see, there's a bit of waste, but it's mostly down to me not yet optimizing things. The properties UDT is particularly wasteful, but with another list (and more complexity) I could shrink that down.

Now, try doing something like that without allowing dynamic arrays in types, i'd end up with 2 distinct arrays. A window and gadget array. The gadget array would have to have an ID field referencing the window it belongs to. I would have to scan each index to find the window it belongs to, and this would be very slow because you could have dozens of buttons and widgets. Every time you needed to update the buttons in a window scan the list (probably every loop).

I could cache the associations in a 3rd array, but since I can't have dynamic arrays in dynamic arrays, I'd need a distinct array for each window. This means my gui system cannot really be dynamic and have caching.

I could have one cache array for the current window, I guess that would be a good tradeoff.

Anyway, my point is, we're starting to deal with caching and crazy unlinked (but theoretically linked) structures and it's a big mess.

With my array, in may seem a bit jumbled, but it's all linked in code, and in the debugger it gives an output just like what I posted here. It's *awesome*

And this isn't useful just for guis, but think of a NPCs inventory. How would you program that? You'd have a dynamic array storing all of the items in inventory. But what if you want a variable number of NPCs with a variable number of inventory items. You're hosed again

So yeah, they're complex, but it's nice to work with. That said, memory on these phones is limited, so if I can't even take advantage of it (you'd know better than me) then feel free to ignore me

[center]
Join the TGC Group!
http://tehcodez.groups.live.com
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Mar 2011 12:18
@Jerico2day
The easiest way to work-around that is to use an ID system like in DBPro, and refer to an array item by its index. Instead of removing items from the array, set a boolean value so you know it's free, and then reuse it next time you create a control or window. Alternatively you can use IanM's freelist commands to acheive the same thing but faster.

[b]
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Mar 2011 15:05
Yeah, but won't work for AppGameKit though ... no plug-ins yet

LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 7th Apr 2011 05:34
I can see a few uses myself, it's just the return on investment (and might take more than 8 weeks too if the current system plays silly buggers with the new additions; remember you can have infinite combinations of things in the real-world, and they all need testing). For your scenario about characters with inventories, I also would implement some sort of simple list system. This would allow you to scan through your lists quickly without consuming any more memory than absolutely necessary. All the arrays in the list system remain global, and can be accessed from anywhere in your program. I DO see the benefits of dynamic arrays in types, but I also see the army of nasty looking gremlins behind those benefits and once you open the gate, you're up to your eyeballs in them

I drink tea, and in my spare time I write software.

Login to post a reply

Server time is: 2024-04-23 11:11:08
Your offset time is: 2024-04-23 11:11:08