
-----------------------------------
atrain
Tue May 31, 2005 12:08 am

complex data importation
-----------------------------------
Im trying to import data in sets of 5 (4 coords, 1 object type) from more than 1 file
im using a flexable 2d array per set

I can get it to detect how many files and open them in order, but getting the data into the array i messed something up...

If you see how u can help, plz do...


var objects : flexible array 1 .. 1, 1 .. 5 of int % New object handling system
var numberoflevels : int := 0
var numberofsets : int := 0
var null : int

procedure getlevels
    var file : int
    var file2 : int
    loop
	numberoflevels := numberoflevels + 1
	exit when File.Exists ("map" + intstr (numberoflevels) + ".t") = false

    end loop
    numberoflevels := numberoflevels - 1 % Last thing broke, remember?
    
    
  for i : 1 .. numberoflevels

	open : file, "map" + intstr (i) + ".t", get
	loop
	    exit when eof (file)
	    get : file, null
	    numberofsets := numberofsets + 1
	end loop

	numberofsets := numberofsets div 5 % FIND OUT HOW MANY OBJECTS
	

	close (file) % CLOSE AND REOPEN
	open : file2, "map" + intstr (i) + ".t", get

	for j : 1 .. numberofsets
	    loop
		exit when eof (file2)
		numberofsets := numberofsets + 1
		for k : 1 .. 5
		    get : file2, objects (j, k)
		end for
		new objects, numberofsets, 5

	    end loop
	    close (file2)
      end for
    end for
end getlevels
getlevels

for i : 1 .. numberofsets - 1
    for j : 1 .. 5
	put objects (i, j)
    end for
end for



-----------------------------------
Delos
Tue May 31, 2005 2:39 pm


-----------------------------------
Woah...no need to get so complicated!
You know the exact structure of each file and its contents.  So extract the entire file into a flexible array and then sort through the array to find what you need.
Or you could do that dynamically, but that's a lot more challenging.
If you absolutely must, add flags to your objects.  So, the set of 5 numbers could begin and end with "#" or something like that, and any other 'objects' you have could be handled similarly.

A few pointers:
It's great that you're using procedures, please keep that up.  But in the immortal words of Cervantes:
"
variable1 := variable1 + 3
% *Rewrite*
variable1 += 3
% These mean the same.


Just a minor point, you needn't have 2 seperate file streams if you're only ever going to have 1 file open at a time.  Once you've close "file" you can use it again to open the files once more.  It's just that expendable!

-----------------------------------
atrain
Tue May 31, 2005 4:37 pm


-----------------------------------
Nah, i figured it out...

basicly, the file structure is sets of 4 coordanates (x1, y1, x2, y2) then a object type

With that i was importing from every map instead of 1

I fixed it

first it finds how many files
then it probes inside the one u chose to find how many sets

then it does 2 for loops

for i: 1..numberofsets
for j: 1..5
get : file, objects (i,j)
end for
end for

So it works great now....
Thanx anywayz!
