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 / Using DIM to extend arrays

Author
Message
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Jul 2013 15:57
Since AppGameKit still doesn't have the list commands of DBP, I am thinking of using DIM to increase the size of arrays. It's not as practical but I wonder if this method is safe, or can I run into problems? I am storing the length of the array in a global variable. When I want to increase the size of the array I simply INC the variable and DIM the array with the new value.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jul 2013 16:21
hmm, works somehow but i missing a description about redim in docu.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 24th Jul 2013 16:25 Edited at: 24th Jul 2013 16:49
You can use dim to resize an array. But it doesn't guarantee that the data will be maintained. This applies especially to multi-dimension arrays. Arrays of UDTs (user defined types) don't always re-dim well either. (Unless they have fixed those bits.)

There is a confirmed issue that is more than a year old that has apparently been ignored.

There is another issue related to arrays and UDTs that is also old and untouched (even though this one is listed as accepted).

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Jul 2013 16:41
I plan to use UDT arrays. I have tested this on a small array and it works so far. But I am writing my own GUI functions and I wonder if I am going to run into problems down the line.

AL:
Both of your links are to the same page.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jul 2013 16:50
udt looks ok
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 24th Jul 2013 16:58
Sorry about that. I fixed the link. I copied the wrong one.

In part because of the problems I was having with UDTs in arrays and strings (v1076), I switched to Tier 2 and now use std::list and std::vector for handling structures.

Stay away from multi-dimensioned arrays with UDTs. They may or may not have fixed that issue. I haven't tested a lot of the older issues lately.

If I had a single dimensioned array, the best way to ensure that I accessed objects in the array properly was to always copy the array entry into a local variable (or global) that is of the same UDT. Then use that variable to access the UDT values. If you make any changes to the UDT, make sure to copy it back into the array.

And definitely don't directly copy from one UDT array into another. Use an intermediate variable of the same type.

Of course, they may have fixed all the Tier 1 issues with UDTs in arrays. I suggest trying simple tests.

Another open issue deals with passing UDT values between functions.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jul 2013 17:12
i belive passing UDTs to functions works if they are defined global
and not local inside a function.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 24th Jul 2013 18:45
Thanks for the links

swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 25th Jul 2013 00:00
I have always stored my UDTs in arrays in this manner and it has been fine. I haven't attempted a multidimensional variant though.

swis
Joined: Tue Dec 16th 2008
Interstellar
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 25th Jul 2013 00:07
I believe I had the same problems AL describes before I moved over to T2 (also because of the problems). I had a 2D array of UDTs and on seemingly random ocations, the variables seemed to be equal to 0 instead of the actual values. Luckily though, the problems happned in the same places every time the program was run and if you created a temporary variable and gave that the value from the array, the problem went away. The only problem was that it was extremley hard to track down the issue and even harder to find a solution for it.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jul 2013 00:09
Thanks, not planning to use multi dimensional arrays anyway.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 25th Jul 2013 10:13
Quote: "i belive passing UDTs to functions works if they are defined global
and not local inside a function."

Surely if the UDT is global it doesn't need passing to the function.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jul 2013 10:43
Marl:
Even though they are global, passing UDTs to a function means that you can use the same function on multiple UDTs that are the same. I feel I am missing a word here, hope you got my point

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 25th Jul 2013 12:28
AL:
It didn't take me long to run into the passing UDTs between functions problem. I'm using a type for colors and had to run the values through a global UDT to make them work. Seriously needs fixing.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Jul 2013 12:56
@Marl
global uts are only a workaround i do not want.
this don't work correct, the same with udt returns
Function Bla()
local a as udt
...
DoIt(a)
Endfunction
Function DoIt(a as udt)
Endfunction
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 26th Jul 2013 05:06
I have had no issues resizing an array by reusing Dim, be it multi dimensional and/or including a type. Although I don't tend to use functions, only gosubs, "listens to sharp intakes of breath from fellow coders". I'm just old fashioned, and gosubs can work just as well, they just take a bit more care and attention.
So for me I have had no real issues with arrays at all, and have avoided most issues. At last my Spectrum programming roots pay off!
Still, it sounds as if there are still issues with AppGameKit regarding this, and it should be sorted out. Functions can be incredibly useful after all, despite my coding preferences!

Login to post a reply

Server time is: 2024-11-24 19:07:36
Your offset time is: 2024-11-24 19:07:36