What on earth is wrong with my save function?!?
BlitzMax Forums/BlitzMax Programming/What on earth is wrong with my save function?!?
| ||
| Apparently I'm doing something wrong here... when this function is called into play it saves a file but there seems to be no data in it... Its almost an exact copy of the save function I was using in Blitz 3D. So what could I be doing wrong here? |
| ||
| Change closestream to closefile. I would also recommend you start using strict mode as it makes debugging a hell of a lot easier. Last edited 2011 |
| ||
| I think we need more information -- it looks fine to me. (I'd have a check for file being non-Null, but if it's creating a file then that's not the problem.) This works for me, for example: Global bg_list:TList = CreateList () Type bg_pal Field typ:Byte Field layer:Byte End Type Function save_data(tfile$) file=WriteFile(tfile) For bg:bg_pal=EachIn bg_list WriteByte(file,bg.typ) WriteByte(file,bg.layer) Next CloseStream(file) End Function For loop = 1 To 10 bg:bg_pal = New bg_pal bg.typ = Rand (0, 255) bg.layer = Rand (0, 255) ListAddLast bg_list, bg Next save_data "test.txt" Is the file 0 bytes in size for you? |
| ||
| Probably that bg_list is empty? :-) |
| ||
| @blitzsupport yeah, the file is empty.. like the data isn't getting out or something. I'll try your code out and see if it fixes it. |
| ||
| no progress... so now last resort... here's all the code I have. :P Tile Data Editor.bmx Palette Data.bmx Tile Data.bmx |
| ||
this works for me:
Global bg_list:TList = CreateList ()
Type bg_pal
Field typ:Byte
Field layer:Byte
End Type
Function save_data(tfile$)
file=WriteFile(tfile)
If file = Null Print "unable to open "+tfile End
For bg:bg_pal=EachIn bg_list
WriteByte(file,bg.typ)
WriteByte(file,bg.layer)
Next
CloseStream(file)
End Function
For loop = 1 To 10
bg:bg_pal = New bg_pal
bg.typ = Rand (0, 255)
bg.layer = Rand (0, 255)
ListAddLast bg_list, bg
Next
save_data "test.txt"
file = ReadFile("test.txt")
While Not Eof(file)
Print ReadByte(file)
Wend
CloseStream(file)
what operating system are you using? Last edited 2011 |
| ||
| Win XP sp3 |
| ||
| it might be your modules. Try to rebuild them. |
| ||
| you are not using bg_list. only bgp_list. so, bg_list is empty. |
| ||
| Hmm... re: my previous post.. :-) Which was the only logical reason for an empty file to be created... |
| ||
![]() dohoho I made a funny. and derp Thanks guys for the help :) |
| ||
| Just to reiterate, if you'd been using Strict mode your original code would not even have compiled, and the error would have been caught immediately. |
| ||
| how do I switch modes? I'm still using the BMax trial version if that helps |
| ||
| By putting Strict or SuperStrict at the beginning of your code. One is more strict than the other. I use SuperStrict myself. |
