(This is from a previous post of mine, only under a more accurate topic post) Okay, I must be doing something glaringly wrong here but I now have another problem. I've written my tilemap editor and I can, of course place and reset my tiles. I'll make my editor a bit more sophisticated once I can figure out why I'm unable to save/load data from the files it's supposed to make.
\\\\\\\\\\\\\\\\\\\\\\\my variables
mapwidth = 150
mapheight = 150
dim tempmap(mapwidth, mapheight)
dim mapspr(mapwidth, mapheight) \\\\\\\\\\I thought I'd use sprites for a bit but I use this to get tile ID #s instead.
for ly = 1 to mapheight
for lx = 1 to mapwidth
mapspr(lx, ly) = ((ly-1)*mapheight)+lx
next lx
next ly
dim map(mapwidth, mapheight)
for ly = 1 to mapheight
for lx = 1 to mapwidth
map(lx, ly) = 0
tempmap(lx, ly) = map(lx, ly)
next lx
next ly
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\my save and load functions
function savemap()
if file exist("map.dat")
delete file "map.dat"
endif
open to write 1, "map.dat"
write byte 1, mapwidth
write byte 1, mapheight
for ly = 1 to mapheight
for lx = 1 to mapwidth
write file 1, map(lx, ly)
next lx
next ly
close file 1
text 200, 10, "Map Saved"
sync
wait 1000
endfunction
function loadmap()
if file exist("map.dat")
open to read 1, "map.dat"
read byte 1, mapwidth
read byte 1, mapheight
for ly = 1 to mapheight
for lx = 1 to mapwidth
read file 1, tempmap(lx, ly)
next lx
next ly
close file 1
text 200, 10, "Map Loaded"
sync
wait 1000
endif
endfunction
\\\\\\\\\\\\\\\\\\\\\\\right after this function,
for ly = 1 to mapheight
for lx = 1 to mapwidth
map(lx, ly) = tempmap(lx, ly)
next lx
next ly
\\\\\\\\\\\\\\\\\\\\\\to put the tiles in place
A bit of assistance please? Everytime I load the files, all of the tiles reset to 0 (the default image) even though I saved a previous file. Also, I've tried opening the dat file and it doesn't show anything, it's just a blank file. (even though I tried saving stuff to it)
Thank you much.
~(A bit later)~
Okay, turns out I'm unable to save anything or something. I've tried saving things like strings or variables but I'm unable to load them. I think it has to do with the way I've saved them but I don't know what it is (I used the same function above and tried .dat, .txt, and other random letters). I seem to be able to insert loaded things back into my program but none of my files have anything on them when I save them. Anybody see anything wrong with my save code?
I used to be the Great Mighty Poo until...