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 / database structure

Author
Message
xsankyo
14
Years of Service
User Offline
Joined: 13th May 2010
Location: Italy
Posted: 17th Sep 2011 11:48
Hello everyone and sorry for my bad English.

I\'m trying to build a small game, like space trader.

my problem is how to structure the necessary information in an array.

data are as follows:

STAR MAP

SOLAR SYSTEM (number, position on star map, explored or unexplored, type of star, number and position of planets)

PLANET (number, position, explored or unexplored, type of planet, material to be collected or extract, presence of a starbase)

MATERIAL to collected (name, weight, maximum amount on the planet)

is it possible to use simple array without using an external database?
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 17th Sep 2011 16:05
Yes, there are a few different ways. If you have only a few planets (say three) per solar system, then you can create types within types like this:


but this means you can't scan planets directly, or loop over multiple planets.

A more complex way is to create an array of solar systems and an array of planets, but include in the solar system the index at which the first planet may be found.



To loop over all planets in a solar system, just call


The solarSystemList array tells you where to start looking in the planetList array, and also how far to keep looking. The only snag is that you can't easily add planets to a solar system mid-game (but I doubt that would be an issue). Create and fill your arrays at startup, and then don't alter them at all.

One more thing, using data types also allows you to call "Array Insert At Bottom", etc. to easily set up the database. You don't need to know how many planets will exist in total, you can just keep adding more as needed.

Hope this helps!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
xsankyo
14
Years of Service
User Offline
Joined: 13th May 2010
Location: Italy
Posted: 18th Sep 2011 11:30
Thanks, I'll try this solution, it seems to me simple and effective
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 20th Sep 2011 02:33 Edited at: 20th Sep 2011 03:03
It would be nice is if you could have an array of a UDT inside another UDT (or an array inside a UDT). Unfortunately DBpro doesn't allow this. Very similar to what was mentioned above, (in where it's suggested you have an array that hs an index into another array), is using parallel UDT arrays. I think Parallel arrays is simpler to manage and loop through IMHO.

This is something that IanM posted many years ago, and has worked for me on similar occasions. I think it's simple enough to see what the intent is.

IanM's example speaks for itself, I think.
Parallel arrays


Let me know if I need to explain it more. Briefly, in your case, SpaceShips would be SolarSystem and SpaceShip_Limbs would be of type planet. Hence the index of the first is built into the first dimension of the second. If you needed more arrays in parallel say a 3rd the first two dimensions would be built into the next array. So say there were a 8 Material User-defined-Types on each planet, 10 Planet types in each SolarSystem, and say 100 SolarSystem types. It would be built in as...



NOTE: I am not including the 0 index of arrays to avoid confusion.

Your signature has been erased by a mod please reduce it to 600 x 120.

Login to post a reply

Server time is: 2024-11-24 01:34:57
Your offset time is: 2024-11-24 01:34:57