Help With Dealing and Sorting Varibles

BlitzPlus Forums/BlitzPlus Programming/Help With Dealing and Sorting Varibles

Ryanenu(Posted 2013) [#1]
What I need is to create a bunch of types like 200+ with say 20 fields each and I need to be able to save, sort, alter, move, and view on demand all this data for my game. I understand the basics involved but am having a hard time wrapping my head around how to perform these tasks.


RemiD(Posted 2013) [#2]
Here is an example to write then to read datas with Types and with Dim arrays.



Also search the forums and the code archive for more examples


Ryanenu(Posted 2013) [#3]
What about sorting these Types? For instance this is what I have right now, it seams to me to be a very inefficient way to go about sorting especially because in my program I will need to sort in this manner A LOT! Is there a more efficient way to sort and display type fields? I assume maybe I need to use a function?



Also how would I go about saving a whole type? Would I need to do something like this?
 
fileout = WriteFile("mydata.dat")

For draft.player = Each player
	WriteByte( fileout, draft\ovr )
Next	


If so how would I go about reloading the integers back into a type so they can be processed again by the program?


_PJ_(Posted 2013) [#4]
filein=ReadFile("mydata.dat")
While Not(EoF(filein))
    draft.player = New player
    player\over=ReadByte(filein)
Wend

You may need some control over the data read in, especially if there are different data types within the file.

___

With regards to Sorting, you may prefer to use some form of hashing rather than re-position each and every element.

Const HASH_BEFORE=0
const HASH_AFTER=1

Dim HashArray(count,2)
HashArray(0,BEFORE)=Handle(First player)
For (x=1 to count-1)
 HashArray(x,BEFORE)=Handle(After(Object.player(HashArray(x-1,BEFORE)))
 HashArray(x-1,AFTER) = HashArray(x,BEFORE))
Next