mzgjan Posted October 30, 2012 Share Posted October 30, 2012 Hellou 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... expandcollapse popupFUNCTIONS: 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 )TF2Server.au3 Link to comment Share on other sites More sharing options...
LurchMan Posted October 30, 2012 Share Posted October 30, 2012 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. mzgjan 1 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 More sharing options...
mzgjan Posted October 30, 2012 Author Share Posted October 30, 2012 ok ill give it a try thanks Link to comment Share on other sites More sharing options...
Spiff59 Posted October 30, 2012 Share Posted October 30, 2012 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 More sharing options...
kylomas Posted October 30, 2012 Share Posted October 30, 2012 (edited) And you have what looks like an orphan case stmt using the file handle. Edited October 30, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now