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.

Newcomers DBPro Corner / Storing Data

Author
Message
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Jan 2004 14:32
I have a bunch of information I want to store in... well, anything, that's what my question is, what to store it in really. I have an unknown number of objects in the scene, and for every object in the scene I will have an unknown number of limbs for it, and for every limb there will be 3 values. So for instance, Object 1 might have 5 limbs, and for each of those 5 limbs I want to store 3 values. Object 2 might have only 1 limb though. What's an ideal way to store this type of information?

I thought about arrays, having something like this:
ArrayName(ObjectNumber,LimbNumber,3)

So then I could easily specify which object number, which limb and which of the 3 values I wanted, however, every object has a different number of limbs so that rules that option out. Next I thought I might use a Type of some sort, perhaps like this:

Type Name
Limb(LimbNumber, 3)
EndType

Dim ArrayName(ObjectNumber) As Name

Then I could do ArrayName(2).Limb(3,2) and it would get Object Number 2, Limb3 and the 2nd value. Pefect I thought. But of course you can't have arrays within Types.

This is really frustrating so hopefully someone can see the predicament I'm in and knows how I can get around it. Is there any way of storing data that can satisfy what I want to do? Anyway at all? Thanks.


"Computers are useless they can only give you answers."
Mougli
20
Years of Service
User Offline
Joined: 10th Dec 2003
Location: United Kingdom
Posted: 21st Jan 2004 17:02 Edited at: 21st Jan 2004 17:03
You'd probably have to use arrays because if your doing this in classic it doesnt support types/structs .

This might not work but have your thought of using a different array for each object that just stores the limbnumber and the three values?

you could use "perform checklist for limbs to check however many limbs the object has and then dim the array like "dim 'name'(limb amount,3)"

Is the glass half empty - or half full?
you can have it all - Just not all at once
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 21st Jan 2004 17:20 Edited at: 21st Jan 2004 17:23
Type limbType
objectID as integer
limbID as integer
limb1 as float
limb2 as float
limb3 as float
EndType

Dim limbList(0) As limbType

` Then use this code to grow the list as needed.

ARRAY INSERT AT BOTTOM limbList(0)

` you should maintain your own list length variable

limbListIndex = limbListIndex +1

` I use something similar to this to store data for a level
` editor that I wrote.
--
TAZ

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 21st Jan 2004 18:38
yes what Zircher said seems correct. Make a type with Obj ID an emptylimb element up to the max limb number of elements, then array the type. Fill each bucket as necessary, write to a file. Read in from file into the same structure to restore.

-RUST-
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 22nd Jan 2004 06:12
No, see the problem is the number of limbs varies from object to object so I can't have a set number of limbs. Well I could, but that would waste quite a bit of memory. I also can't use seperate arrays because that would mean defining a different array for each object wich there could be hundreds of.


"Computers are useless they can only give you answers."
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd Jan 2004 06:26
well instead of the type, mabye a multi dimesioned array would work since you can redim arrays with array insert as mentioned above. maybe first tier of array would hold reference to object number then the second tier could grow and shrink with the amount of limbs for that particular object. Might work.

let's say object 2 had five limbs you could store the data in the following array indexes:

2,0
2,1
2,2
2,3
2,4

if object 2 then needed an extra limb you could redim to use 2,5

not sure about this in dbp but theoretically it should work.

-RUST-
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 22nd Jan 2004 08:05
Yeah, but what if object 3 had only 2 limbs? The array would be good for object 2 but too large for object 3, I guess it wouldn't matter too much but I was looking for something more effective. If there's no other option then I may as well go with that.


"Computers are useless they can only give you answers."
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Jan 2004 09:31
What you want is a linked list ...

The following code was for a tile-based system that would allow you to position as many units to a tile as you wish (it was for a war strategy game I think). You should find it relatively easy to adapt to what you want (Tile_t becomes your object type, Unit_t becomes your limb type)



For free Plug-ins, source and the DBPro Interface library for Visual C++ 6 and .NET
http://www.matrix1.demon.co.uk
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd Jan 2004 17:08
exeat,

3,0 and 3,1 ?

maybe I am not understanding the problem - wouldn't be the first time

-RUST-
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 22nd Jan 2004 17:19
Look closer, Exeat. You're missing something important.

Type limbType
objectID as integer
limbID as integer
limb1 as float
limb2 as float
limb3 as float
EndType

The values limb1, limb2, limb3 are NOT the limbs. They are the three values that each limb has. The limbID value has the limb number and you can have as many objects or limbs as you want, each with three values.


` Object 1 with 1 limb
ARRAY INSERT AT BOTTOM limbList(0)
index = 1
limbList(index).objectID =1
limbList(index).limbID = 1
limbList(index).limb1 = 0.0
limbList(index).limb2 = 0.0
limbList(index).limb3 = 0.0

` object 2 with 2 limbs
ARRAY INSERT AT BOTTOM limbList(0)
index = index+1
limbList(index).objectID =2
limbList(index).limbID = 1
limbList(index).limb1 = 0.0
limbList(index).limb2 = 0.0
limbList(index).limb3 = 0.0

ARRAY INSERT AT BOTTOM limbList(0)
index = index+1
limbList(index).objectID =2
limbList(index).limbID = 2
limbList(index).limb1 = 0.0
limbList(index).limb2 = 0.0
limbList(index).limb3 = 0.0

--
TAZ

Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 23rd Jan 2004 13:24 Edited at: 23rd Jan 2004 13:25
Yeah, it's just all the data is hard to access because it can be out of order as new limbs/old limbs are added (I know, I'm fussy ). I'm going to use a variation of IanM's code, thanks everybody!


"Computers are useless they can only give you answers."

Login to post a reply

Server time is: 2024-09-21 18:43:58
Your offset time is: 2024-09-21 18:43:58