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.

DarkBASIC Professional Discussion / multidimensional array questions

Author
Message
Turoid
22
Years of Service
User Offline
Joined: 1st Nov 2003
Location: The Netherlands
Posted: 29th Apr 2011 21:25
Hello

Just picked up dbpro again in my spare time, have some questions about array's.

For example, I want to add an element at the second index of this array:

NOTE: psuedo code kind of



Another question. How can I get the seperate array count values of this array. I want to know the count of index 1 itself, but also per index the count of the second index. Like so:



I can imagine it could be quite difficult for you guys to understand what I'm asking. But the array commands for adding, removing and counting array elements just don't work that well for me. Unless I'm using them wrong, which I think is the case.

Also I couln't find any clear examples which showed me a solution. I know about redimming, but then I still have the issue of 'counting' the amount of elements from a second or third element in an array.

Thanks in advance
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 29th Apr 2011 21:29
You cannot have dynamically sized multi-dimension arrays. Meaning, they can't grow through use (adding an element) without the redim command first. You might want to look into DarkData if you're trying to use a fancy table type data structure.


A 3D marble platformer using Newton physics.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 29th Apr 2011 21:32
You're referring to treating the array as an object, and it doesn't work that way in DBP.

dim MyArray(10) as string
MyArray(1) = "one"
MyArray(2) = "two"
...

Simple no frills BASIC.

The count of the first index is the important one. You have to set the second one when you create the array, and that's what it stays at. You can't add or subtract from the second index at runtime.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Apr 2011 02:09 Edited at: 30th Apr 2011 02:14
You can resize and existing multi-dimensional array - you simply use the DIM command on it again:


[edit]Just read the last bit of the original question.

Quote: "but then I still have the issue of 'counting' the amount of elements from a second or third element in an array."

There is no such thing. DBPro arrays are rectangular.

DIM a(10,10) will define an array of 11 by 11 cells (numbered from 0 to 10). DIM a(1, 2, 3) will define an array of 2 by 3 by 4 cells. You can't have line 0 of the array a different size from line 1 etc.

[one more edit]Rather than ask us how to implement your solution, why not tell us what the problem you're trying to solve is.

Turoid
22
Years of Service
User Offline
Joined: 1st Nov 2003
Location: The Netherlands
Posted: 30th Apr 2011 15:06 Edited at: 30th Apr 2011 15:08
Thanks all for the replies I now better understand how arrays work within DBPro.

I currently use DBPro to do some prototyping of algorithms I find interesting. Much faster to do these kind of things with DBPro rather than setting up a complete project using SDL for example.

I found this work around:



You might wonder where this all is for. Some time ago I did an attempt on a* pathfinding, which used a 'grid' to calculate everything. I found that this grid was quite limited, also not as optimized as a custom 'navigation mesh' for example could be. Therefor I wanted to try something with nodes linked together to let my a* search on.

Got it working, you can view it here http://www.youtube.com/watch?v=98RNGFv9h9Q

Thanks again, DBPro is really nice for quick prototying of ideas for this kind of little systems. Though I would like to have a feature which lets us use arrays within types, solves a lot of issues !
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 30th Apr 2011 17:18
That's pretty cool. Nicely done.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Apr 2011 21:54
@Turoid
I made a DBPro plugin for node based A* pathfinding

[b]
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 1st May 2011 04:41
Also nicely done.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st May 2011 13:33
@Turoid,
Call me a naysayer, but I'm not sure that I see anything great about your solution, or why it even works

1. If the first dimension can change, then if the second row of the 2-D array has less items in it that the first row, you'll lose most data in the first row if not careful. (I suspect he has NOT used this method).



2. If you're simply using it as a 1-D array (ie, the first dimension never changes size), then you may as well use a 1-D array rather than have the extra dimension and double the memory usage. (It doesn't sound like he's done that either).

Either you've not explained the whole solution, or your code is working by coincidence (at least as far as I can see).

DLS
22
Years of Service
User Offline
Joined: 6th Jul 2004
Location: Wet And Windy Britain
Posted: 2nd May 2011 01:37
i remember back when i was in college playing with VB they had a redim command that allowed you to grow an array iirc

but that was a long long time ago and i may now be barking up the wrong tree. still would be a handy feature to have i guess

PC spec: AMD Phemon II X4 940@ 3Ghz, 8Gb DDR2 Ram, 1x 60Gb SSD and 2x 500 gb HDD, GForce STX260 876Mb, Windows 7 64bit
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd May 2011 15:26
DIM does the same job for DBPro. To lose the data in an array, you need to actually UNDIM it before re-DIM-ing it to its new size.

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 2nd May 2011 16:55 Edited at: 2nd May 2011 16:57
Well, as DB had problems when first released with resizing arrays, I have always gone down the route of simply making them larger than needed. Not super efficient, but it generally works ok. Still it could cause issues if you need to check through lots of data I suppose. Does anyone know if the array commands actually work ok now?



I never had any luck using these commands in the past and so have ignored them for years. I tend to use old school methods with arrays rather than these commands, which so far has been fine. As IamM mentioned, undim and then diming an array again should work, you just have to put the data back into it afterwards.

http://s6.bitefight.org/c.php?uid=103081
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 2nd May 2011 18:18
Those commands unfortunately only work for 1D arrays but they do work well. What I do on my current project (a huge database) when I need one more record beyond the array size I redim it for 100 more elements.



Agent
21
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 3rd May 2011 08:00
I can confirm that these array commands do work, but I'm not a fan of automatic processing like this. I think it's a better idea to resize the array manually, and deploy your data to the newly defined element.

Can't rightly say why I don't like the array commands. It just feels like an automated process, and I hate anything automated. I like to work at the lowest possible level when coding (I don't like using plugins unless they are truly excellent, for example).

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th May 2011 17:46
Agent, I tend to feel the same way. Although after playing about trying to get DB to have a decent text input, I sometimes think a nice VB text box would be very useful. I mainly only have a problem with automation if it slows things down too much though. If it ran as fast and introduced no bugs I would probably be happy enough.

http://s6.bitefight.org/c.php?uid=103081

Login to post a reply

Server time is: 2026-07-11 04:24:32
Your offset time is: 2026-07-11 04:24:32