What on earth is wrong with my save function?!?

BlitzMax Forums/BlitzMax Programming/What on earth is wrong with my save function?!?

AvestheFox(Posted 2011) [#1]
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?




GfK(Posted 2011) [#2]
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


BlitzSupport(Posted 2011) [#3]
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?


Brucey(Posted 2011) [#4]
Probably that bg_list is empty? :-)


AvestheFox(Posted 2011) [#5]
@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.


AvestheFox(Posted 2011) [#6]
no progress... so now last resort... here's all the code I have. :P

Tile Data Editor.bmx


Palette Data.bmx


Tile Data.bmx



Jesse(Posted 2011) [#7]
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


AvestheFox(Posted 2011) [#8]
Win XP sp3


Jesse(Posted 2011) [#9]
it might be your modules. Try to rebuild them.


Zeke(Posted 2011) [#10]
you are not using bg_list. only bgp_list. so, bg_list is empty.


Brucey(Posted 2011) [#11]
Hmm... re: my previous post.. :-)

Which was the only logical reason for an empty file to be created...


AvestheFox(Posted 2011) [#12]


dohoho I made a funny.

and derp

Thanks guys for the help :)


GfK(Posted 2011) [#13]
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.


AvestheFox(Posted 2011) [#14]
how do I switch modes?

I'm still using the BMax trial version if that helps


JazzieB(Posted 2011) [#15]
By putting Strict or SuperStrict at the beginning of your code. One is more strict than the other. I use SuperStrict myself.