Jump to content

FileWrite Problem


mzgjan
 Share

Recommended Posts

Hellou :D

im writing a prog for starting and restarting a steam dedicated server so its easier to manage it.

But now i got a problem: I want to have a save settings function and i wrote one but it doesnt work :/

i tried the _filewritetoline and the filewriteline function but without any sucess... :

FUNCTIONS:

Func loadsettings()
Local $settingsfile = FileOpen(@ScriptDir & "\settings.txt")
Global $loaded_port = FileReadLine($settingsfile, 1)
Global $loaded_maxplayers= FileReadLine($settingsfile, 2)
Global $loaded_map = FileReadLine($settingsfile, 3)
Global $loaded_direction = FileReadLine($settingsfile, 4)
FileClose($settingsfile)
EndFunc

Func savesettings($port, $maxplayers, $map, $direction)
Local $settingsfile = FileOpen(@ScriptDir & "\settings.txt", 2)
FileWriteLine(@ScriptDir & $settingsfile, $port)
FileWriteLine(@ScriptDir & $settingsfile, $maxplayers)
FileWriteLine(@ScriptDir & $settingsfile, $map)
FileWriteLine(@ScriptDir & $settingsfile, $direction)
FileClose($settingsfile)
EndFunc

If FileExists(@ScriptDir & "\settings.txt") Then
loadsettings()
Else
Global $loaded_port = "27015"
Global $loaded_maxplayers= "24"
Global $loaded_map = "plr_hightower"
If FileExists("C:\Program Files (x86)") Then
Global $loaded_direction = "C:\Program Files (x86)\HLServer"
Else
Global $loaded_direction = "C:\Program Files\HLServer"
EndIf
EndIf

______________________________________________-

Case $savesettings
Global $port = GUICtrlRead($input_port)
Global $maxplayers = GUICtrlRead($input_maxplayers)
Global $map = GUICtrlRead($input_map)
Global $direction = GUICtrlRead($input_direction)
If FileExists(@ScriptDir & "\settings.txt") Then
FileDelete(@ScriptDir & "\settings.txt")
_FileCreate(@ScriptDir & "\settings.txt")
savesettings($port, $maxplayers, $map, $direction)
MsgBox(0, "Einstellungen überschrieben", "Die aktuellen Einstellungen wurden gespeichert" & @CRLF & "und werden bei einem Neustart geladen.")
Else
_FileCreate(@ScriptDir & "\settings.txt")
savesettings($port, $maxplayers, $map, $direction)
MsgBox(0, "Einstellungen gespeichert", "Die aktuellen Einstellungen wurden gespeichert" & @CRLF & "und werden bei einem Neustart geladen.")
EndIf

Please help me ...

(I´m from germany, i hope my english is fine enough for u to understand my problem :D )

TF2Server.au3

Link to comment
Share on other sites

Why not use an INI file rather than trying to read / write specific lines within the file? Look at the INIWrite and INIRead Functions in the help menu.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

You've created a file handle to your open file.

And when you go to write to it...

Oops!

Local $settingsfile = FileOpen(@ScriptDir & "settings.txt", 2)
FileWriteLine(@ScriptDir & $settingsfile, $port)
FileWriteLine(@ScriptDir & $settingsfile, $maxplayers)
FileWriteLine(@ScriptDir & $settingsfile, $map)
FileWriteLine(@ScriptDir & $settingsfile, $direction)
FileClose($settingsfile)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...