I wonder if glbasic can save\load matrix in files(dat for example) as it can fenix? I need to load map like this:
1 1 1 1 1
2 1 1 2 1
2 1 2 1 2
...
but a lot of bigger.
Or i only can save it in text file one by one?
Thanks in advance and sorry for my english.
FUNCTION WriteArray: a[]
OPENFILE 1, "out.bin", false
writelong 1, len(a[])
writelong 1, bounds(a[], 1)
for x=0 to len(a[])-1
for y=0 to bounds(a[],1)-1
writeieee 1, a[x][y]
next
next
closefile 1
endfunction
It says: syntax error on second string of function =\
EDIT:
Now i see, not
OPENFILE 1, "out.bin", false
,but
OPENFILE (1, "out.bin", false)
Quote from: GernotFrischFUNCTION WriteArray: a[]
OPENFILE 1, "out.bin", false
writelong 1, len(a[])
writelong 1, bounds(a[], 1)
for x=0 to len(a[])-1
for y=0 to bounds(a[],1)-1
writeieee 1, a[x][y]
next
next
closefile 1
endfunction
hi, could you please tell me how it works? i am a noob in glbasic, so i didn't understand really well this code... but i think it could be a useful function.
thanks a lot! bye :)
I'll try to explain :-)
FUNCTION WriteArray: a[]
OPENFILE 1, "out.bin", false // Open a file to write to
writelong 1, len(a[]) // write the size of the array to the file so we can open it up later and know
writelong 1, bounds(a[], 1) // how big the array is supposed to be to contain the data
for x=0 to len(a[])-1 // Run thru the array and write each number to the file
for y=0 to bounds(a[],1)-1 // incrementing x and y in turn so we walk thru the whole array
writeieee 1, a[x][y] // write the number at x, y to the file
next
next
closefile 1
endfunction