openfile\writefile help!

Blitz3D Forums/Blitz3D Beginners Area/openfile\writefile help!

ahh this isnt working, it keeps adding zero to the file!some 1 plz help!!
Function save_settings()
	If FileType("settings.txt") <> 1 Then WriteFile("settings.txt")
	file=OpenFile("settings.txt")
	WriteLine(file,mousebutton1_assign)
	WriteLine(file,mousebutton2_assign)
	WriteLine(file,mousebutton3_assign)
	CloseFile(file)
End Function

Function load_settings()
	If FileType("settings.txt")
		file=OpenFile("settings.txt")
		mousebutton1_assign=ReadLine(mousebutton1_assign)
		mousebutton2_assign=ReadLine(mousebutton2_assign)
		mousebutton3_assign=ReadLine(mousebutton3_assign)	
		CloseFile(file)
	EndIf
End Function


Coupla' problems I can immediately spot:

If FileType("settings.txt") <> 1 Then WriteFile("settings.txt")
You're not assigning WriteFile to anything, and if you intend to overwrite the file contents then you should always be accessing it with WriteFile rather than trying to create it then OpenFile it. OpenFile will tack the new data on the end (erm, or at least allows you to). Also what if "settings.txt" is a directory for some bizarre unforeseen reason?

mousebutton1_assign=ReadLine(mousebutton1_assign)
Should be a stream in the parenthesis there.

Is the any reason why you're not using Read/WriteInt()?

EDIT: Also check that the variables you want to save are global otherwise they WILL all be freshly initialised local zeroes within the functions.

Anyway, try...
Function save_settings()
	If Not FileType("settings.txt") = 2 ;If file is not a directory
		file=WriteFile("settings.txt") ; Overwrite settings.txt
			WriteLine(file,mousebutton1_assign)
			WriteLine(file,mousebutton2_assign)
			WriteLine(file,mousebutton3_assign)
		CloseFile(file)		 
	Else
		RuntimeError("WTF?! seti|\|z iz dir3ctorzry LOL!");Don't do error messages like this
	EndIf
End Function


Function load_settings()
	If FileType("settings.txt") = 1
		file=OpenFile("settings.txt")
		mousebutton1_assign=ReadLine(file)
		mousebutton2_assign=ReadLine(file)
		mousebutton3_assign=ReadLine(file)	
		CloseFile(file)
	Else
		RuntimeError("OH NOES! seti|\|z gon!!!");No, really, don't.
	EndIf
End Function


Fuller example showing data retrieval:
Global mousebutton1_assign=1
Global mousebutton2_assign=2
Global mousebutton3_assign=3

Function save_settings()
	If Not FileType("settings.txt") = 2 ;If file is not a directory
		file=WriteFile("settings.txt") ; Overwrite settings.txt
			WriteLine(file,mousebutton1_assign)
			WriteLine(file,mousebutton2_assign)
			WriteLine(file,mousebutton3_assign)
		CloseFile(file)		 
	Else
		RuntimeError("WTF?! seti|\|z iz dir3ctorzry LOL!");Don't do error messages like this
	EndIf
End Function


Function load_settings()
	If FileType("settings.txt") = 1
		file=OpenFile("settings.txt")
		mousebutton1_assign=ReadLine(file)
		mousebutton2_assign=ReadLine(file)
		mousebutton3_assign=ReadLine(file)	
		CloseFile(file)
	Else
		RuntimeError("OH NOES! seti|\|z gon!!!");No, really, don't.
	EndIf
End Function

save_settings()
mousebutton1_assign=0
mousebutton2_assign=0
mousebutton3_assign=0
load_settings()

Print mousebutton1_assign
Print mousebutton2_assign
Print mousebutton3_assign

Note that if you open settings.txt in Notepad you'll be able to scroll down to a blank line because WriteLine() adds a line-feed and carriage-return to the data (thus making it a line), which is why you might want to consider Read/WriteInt(). You might even want to use Read/WriteByte() if the numbers are going to fall within the range 0-255.

lol thank's dude! i'll keep in mind those error messages...