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 / Lists of type things in DBPro

Author
Message
EddieRay
23
Years of Service
User Offline
Joined: 28th Feb 2003
Location: USA
Posted: 4th Apr 2003 09:44
Can anyone give me a quick run-down on how I can implement a list of items in DBPro patch 4?

Here's what I want to do:

1) Create an empty array of type things.

2) Add entries.

3) Traverse entries one at a time.

3a) Possibly delete the current item and continue with the next item.

Can someone post a snippet that would use the ARRAY commands to do that? Do the ARRAY commands actually work in DBPro patch 4?

What is up with the "Array Name(0)" syntax? Does that literally mean you have to use something like:

ARRAY INSERT AT TOP myarray(0)

Is it okay to use 0 as an index into an array like this:
myarray(0) = 1
I'm accustomed to arrays with an index starting at 0...

Thanks,

Ed
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 4th Apr 2003 10:55
The array commands are (somewhat) buggy - I prefer to use my LinkList plug-in.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th Apr 2003 17:24
i wouldn't use the Array commands, they're a waste of time (if you can even get them working)

i'd suggest using Toad's LinkList plugin until you get a very good grasp of the Memory and pointer commands ... because its possible with 2 memory blocks using one as a buffer and the other as the expanded data, swap between the two whilst you make the other bigger. its a complex task though

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Mnemonix
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 4th Apr 2003 17:27
I never personally use the stack/array commandset.

When i make lists i use Arrays/User defined types. It plays a big role in my interface engine. Is that what you mean

Where did his Ak-47 go.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Apr 2003 21:25
Hmmm, as long as you know what does and doesn't work, they can be quite useful.

The stack and queue add and remove commands work OK, as does insert and delete from bottom.

Also, I general ignore entry 0 when using an array as a stack or queue, because then the array count function matches what I do.

Here's an example using queues (first in first out)



There are so many ways to use arrays in DB, I can only suggest that you have a play around.
EddieRay
23
Years of Service
User Offline
Joined: 28th Feb 2003
Location: USA
Posted: 5th Apr 2003 01:15
IanM: Thanks for the snip! So, what exactly have you encountered that should work but doesn't?

Mnemonix: I'm doing the same - array of user-defined type things (like IanM's code does above). The problem is that the array will only contain some number of entries that I care about at a given time.



So the part that I'm trying to avoid is scanning the entire array for a "free" slot.

MrTaToad: I'd like to do this without plug-ins if possible.

Raven: Sure, I could use memblocks and pointers, but I'm trying to keep the program "readable", and I don't really know how pointers "work" in DBPro as opposed to C (and don't really care to at this point). It shouldn't be necessary for something this simple.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Apr 2003 01:27
Commands that don't work:
ARRAY INSERT AT TOP
ARRAY INSERT AT ELEMENT
ARRAY DELETE ELEMENT

I don't use the ARRAY INDEX... commands so I don't know whether they actually work - I prefer to use my own index (as shown in my snippit). I *will* be finding out soon though, for a DBDN project ...

Gotchas to remember:
ARRAY COUNT() returns the highest index usable with an array, not the number of entries. So, with a 1-entry array ( dim a(0) ) the ARRAY COUNT() function will return zero.
EMPTY ARRAY() deletes all entries in the array, so ARRAY COUNT() will return -1 immediately after. So it's best to insert a new item after emptying the array.
EddieRay
23
Years of Service
User Offline
Joined: 28th Feb 2003
Location: USA
Posted: 5th Apr 2003 01:43 Edited at: 5th Apr 2003 01:46
Thanks!

It's unfortunate that ARRAY DELETE ELEMENT doesn't work tho'. I can't really do what I want (avoiding scanning the entire array) if I can't delete entries that become inactive... oh well. Have you reported this bug? Any word on when it will be fixed?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Apr 2003 01:55
It's been reported. Should be a part of Patch 5.

An easy way to delete any entry is to just move the last entry over it and then remove the last item (that is safe) - unless you are trying to keep the array sorted of course - then you can shuffle all items up one and delete the last item.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 5th Apr 2003 02:30
problem is this can slow down access quite a bit... especially when you have to do large ammounts of sorting - which isn't good for a game in most cases.
i still use my old DB trick of 2 arrays for the same objects, undim and redim one with the extra entries and then copy across the data...

alternatively i just throw them in a DLL array and grab them that way - its far easier to manage (^_^) but thats just me suppose

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 5th Apr 2003 05:03
Hmmm... it seems like MrTAToad's linked list library is quite useful. I am just curious how does it is implemented? I mean, how do you interface the TYPE in DarkBasic Pro with the DLL (which is most probably written in C++). Do you keep track of all memory consumed by every array created in the DLL as well?

Thanks!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 6th Apr 2003 21:10
Oh... BTW, can we pass TYPE from DBpro to a DLL function?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Apr 2003 01:38 Edited at: 7th Apr 2003 01:39
No, you cant unfortunately... Nor can you pass variable addresses...

Of course my LinkList routine is useful - I always do useful plug-ins...

Ed - What have you got against plug-ins ?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Bulleyes
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 7th Apr 2003 12:18
So how is your LinkedList plugin works? How do you create and access the LinkedList created in your DLL? There is one way that I can thought of is by using the DBpro convention, i.e. every LinkedList created in the DLL can be refered using an integer. While the DLL itself keep a list of LinkedList object created. All the operations on the LinkedList required the integer to identified which LinkedList to operate upon.

Is this a good way? Any good suggestion to further improve it?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Apr 2003 12:56
The LinkList plug-in works in the following way, which is somewhat like your idea:

First of all, you create a header - this returns a number which is passed to most other linklist routines. Something like :



You can then add data to the front, end or middle of the list use AddNode :



The parameters are slight wrong, but it gives the general idea...

To go through the list, you can start at either the front, end or middle and work your way through the list, like so :



You've also got the ability to search for data (text only search at the moment), return data from a specific index, send diagnostic data to a file and sort the list (limited in DBPro because of you cant pass the address of a function). The sorting routine uses a Quicksort.

I've got example code at home, which I can e-mail if your interested.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!

Login to post a reply

Server time is: 2026-07-11 02:36:03
Your offset time is: 2026-07-11 02:36:03