Database Generation

Blitz3D Forums/Blitz3D Programming/Database Generation

Colvette(Posted 2007) [#1]
Hey, Folks,

I'm writing the basis for a little game prototype, and I need to load in a file as a database of names, and need to access the data contained herein as strings.

If I were using "C" (which is where I come from), I'd define the string as a type, then allocate a big chunk of memory as Data Type Size*Number of Names, and access the memory using casting of some kind.

Can anyone suggest to me how I can do this in Blitz? I realise I can't go about it in the same way, but there has got to be a work-around to be able to allocate a large chunk of memory to store data which can be accessed like a list of a specific type?

Thanks in advance for any help!

Col.


GfK(Posted 2007) [#2]
Memory banks?
Arrays?
Custom types?


Colvette(Posted 2007) [#3]
As you can't cast in Blitz, I'm unsure how to use Banks to achieve what I want.

Arrays can't be assigned dynamic sizes.

Custom Types - well, I'd be unsure how to use those to do what I wanted either...?

I basically want to create a dynamic list from the information in a file. Any ideas?


GfK(Posted 2007) [#4]
I'm typing this straight into the reply box, so its untested. Should get you going in the right direction though. Its Blitzmax code as I can't for the life of me remember how types work in BB3D! :(

Global dbList:TList = New TList

LoadDB()
db:dbItem = fetchItem(20)

Function fetchItem:dbItem(pos:int)
  Return dbItem(dbList.ValueAtIndex(pos))
End Function

Function LoadDB()
  FILE:TStream = ReadFile("file.txt")
  If FILE
    Repeat
      Local d:dbItem = New dbItem
      d.s = ReadLine(FILE)
      dbList.AddLast d
    Until EOF(FILE)
    CloseFile FILE
  EndIf
end function

Type dbItem
  Field s:String
end Type



Paolo(Posted 2007) [#5]
It is basically as GfK says,
custom Types are basically lists of as many elements as
you want, you don't need to specify a memory size, you simple
define the "Type" and then you add new elements or erase them
whenever you need to, ... read about Types and you'll see it
is one of the most useful things of the language ...

have a look at the next commands:
OpenFile(), ReadFile(), ReadLine(), ReadString(), EOF()

Also,
arrays CAN be resized anytime-anywhere in the code, although
when you resize it loses the data so you will first need to
pass the data to another "dummy array" to restore after
resizing the real array ...

Paolo.


Colvette(Posted 2007) [#6]
Thanks, Chaps - got it now! :)