Topher Posted April 16, 2012 Share Posted April 16, 2012 This writes the wrong data to file Things are fine to the '; _ArrayDisplay($ArrayOfScores)' line, then the array gets scrambled. help expandcollapse popupFunc HighScore() ; high score pane top most and moveable but nothing else - closes by game pane close $StatID = GUICreate("High Scores", 230, 490, -1, -1, BitOR($WS_EX_TOPMOST, 0), -1, $hGUI) GUISetFont(14, 600, -1, "Courier New") $StatEdit = GUICtrlCreateEdit("", 10, 10, 210, 470) ;FileDelete("Reflex.dat") ; testing ; if no high score file, create it If Not FileExists("Reflex.dat") Then $file = FileOpen("Reflex.dat", 2) If $file = -1 Then MsgBox(0, "Fatal Error", "Can not create high score file") Exit EndIf $temp = StringFormat("%4s%6d", "GACB", 10) For $loop = 1 to 20 FileWriteLine($file, $temp) Next FileClose($file) EndIf ; Load Score Array from file $file = FileOpen("Reflex.dat", 0) ; read only Const $Names = 0 Const $Scores = 1 Dim $ArrayOfScores[2][21] For $loop = 1 to 20 $linescore = FileReadLine($file) $ArrayOfScores[$Names][$loop] = StringLeft($linescore, 4) $ArrayOfScores[$Scores][$loop] = StringMid($linescore, 5, 6) Next FileClose($file) ; Test if new score must be added to scoreboard ; msgbox(0,$Score, $ArrayOfScores[$Scores][20]) If $Score > $ArrayOfScores[$Scores][20] Then $temp = InputBox("New Score for Scoreboard", "Enter Your Initials: ", "", "", -1, 120) $temp = StringFormat("%4s", $temp) $ArrayOfScores[$Names][0] = StringUpper($temp) Else $ArrayOfScores[$Names][0] = " " EndIf $ArrayOfScores[$Scores][0] = $Score _ArraySort($ArrayOfScores, 0, 0, 0, $Scores) ; _ArrayDisplay($ArrayOfScores) ; write high score file $file = FileOpen("Reflex.dat", 2) ; write fresh If $file = -1 Then MsgBox(0, "Fatal Error", "Can not update high score file") Exit EndIf For $loop = 0 to 19 $temp = StringLeft($ArrayOfScores[$Names][$loop],4) ; MsgBox(0,"",$temp) $temp = StringFormat("%4s%6d", $temp, $ArrayOfScores[$Scores][$loop]) ; MsgBox(0, "", $temp) FileWriteLine($file, $temp) Next FileClose($file) ; Display Scores $temp = "" For $loop = 0 to 19 $temp &= StringFormat("%2d. %4s %6d", $loop+1, $ArrayOfScores[$Names][$loop], $ArrayOfScores[$Scores][$loop]) & @CRLF Next GUICtrlSetData($StatEdit, $temp) GUISetState() ; wait until window is closed Do $msg = GUIGetMsg() Sleep(20) Until $msg = $GUI_EVENT_CLOSE GUIDelete($StatID) EndFunc ;==>DisplayStatHistory [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Bert Posted April 16, 2012 Share Posted April 16, 2012 (edited) Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum Rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be reported to a moderator to be locked.See you soon with a legitimate question I hope. Edited April 16, 2012 by MPH The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Topher Posted April 16, 2012 Author Share Posted April 16, 2012 (edited) This is not game automation. In fact there is no animation there at all. This is a high score routine for my game Reflex (see link in sig) Edited April 16, 2012 by Topher [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Bert Posted April 16, 2012 Share Posted April 16, 2012 That will be up to the moderator to decide. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Topher Posted April 16, 2012 Author Share Posted April 16, 2012 I believe in the rules it also talks about merely reporting a post and not engaging the OP in conversation [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 16, 2012 Share Posted April 16, 2012 I believe in the rules it also talks about merely reporting a post and not engaging the OP in conversation But that is about reporting spam .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
4Eyes Posted April 16, 2012 Share Posted April 16, 2012 Topher, Umm, I'm not sure if you meant this: For $loop = 0 to 19 $temp = StringLeft($ArrayOfScores[$Names][$loop],4) ; MsgBox(0,"",$temp) $temp = StringFormat("%4s%6d", $temp, $ArrayOfScores[$Scores][$loop]) ; MsgBox(0, "", $temp) FileWriteLine($file, $temp) Next but there's no point in: $temp = StringLeft($ArrayOfScores[$Names][$loop],4) then throwing that away 2 lines later with: $temp = StringFormat("%4s%6d", $temp, $ArrayOfScores[$Scores][$loop]) To my mind, this thread doesn't contravene the forum rules at all because you're writing your own game in AutoIT and not automating another, but then again I'm not a mod. BTW, without some more code it's hard to see what the problem is. Link to comment Share on other sites More sharing options...
Topher Posted April 16, 2012 Author Share Posted April 16, 2012 Report is to report rule violations of any kind. I fear the poster has killed this thread even though he was wrong. Either that or everyone are also stumped as to the coding problem. I'm sure I've made some hard to see problem; it always turns out to be my mistake [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
Topher Posted April 16, 2012 Author Share Posted April 16, 2012 @Eyes That was my thinking/point about rules violation. I expanded out all the combined segments to try to isolate the problem, thus all the $temp stuff. The only extra code to run it I think would be: Include <array.au3> $Score = 300 Highscore() [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] Link to comment Share on other sites More sharing options...
4Eyes Posted April 16, 2012 Share Posted April 16, 2012 (edited) Topher, I've had a look see as follows: expandcollapse popup#Include <array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $hGUI $Score = 200 Const $Names = 0 Const $Scores = 1 Dim $ArrayOfScores[2][21] Highscore() Func HighScore() ; high score pane top most and moveable but nothing else - closes by game pane close $StatID = GUICreate("High Scores", 330, 490, -1, -1, BitOR($WS_EX_TOPMOST, 0), -1, $hGUI) GUISetFont(14, 600, -1, "Courier New") $StatEdit = GUICtrlCreateEdit("", 10, 10, 310, 470) FileDelete("Reflex.dat") ; testing ; if no high score file, create it If Not FileExists("Reflex.dat") Then $file = FileOpen("Reflex.dat", 2) If $file = -1 Then MsgBox(0, "Fatal Error", "Can not create high score file") Exit EndIf ;$temp = StringFormat("%4s%6d", "GACB", 10) $temp = "GACB 10" For $loop = 1 to 20 FileWriteLine($file, $temp) Next FileClose($file) EndIf MsgBox(0, "", "Check the file") ; 4Eyes - Ok at this point ; Load Score Array from file $file = FileOpen("Reflex.dat", 0) ; read only For $loop = 1 to 20 $linescore = FileReadLine($file) $ArrayOfScores[$Names][$loop] = StringLeft($linescore, 4) $ArrayOfScores[$Scores][$loop] = StringMid($linescore, 5, 6) Next FileClose($file) ; Test if new score must be added to scoreboard ; msgbox(0,$Score, $ArrayOfScores[$Scores][20]) If $Score > $ArrayOfScores[$Scores][20] Then $temp = InputBox("New Score for Scoreboard", "Enter Your Initials: ", "", "", -1, 120) $temp = StringFormat("%4s", $temp) $ArrayOfScores[$Names][0] = StringUpper($temp) Else $ArrayOfScores[$Names][0] = " " EndIf $ArrayOfScores[$Scores][0] = $Score _ArraySort($ArrayOfScores, 0, 0, 0, $Scores) ; _ArrayDisplay($ArrayOfScores) ; write high score file $file = FileOpen("Reflex.dat", 2) ; write fresh If $file = -1 Then MsgBox(0, "Fatal Error", "Can not update high score file") Exit EndIf For $loop = 0 to 19 $temp = StringLeft($ArrayOfScores[$Names][$loop],4) ; MsgBox(0,"",$temp) $temp = StringFormat("%4s%6d", $temp, $ArrayOfScores[$Scores][$loop]) ; MsgBox(0, "", $temp) FileWriteLine($file, $temp) Next FileClose($file) ; Display Scores $temp = "" For $loop = 0 to 19 $temp &= StringFormat("%2d. %4s %6d", $loop+1, $ArrayOfScores[$Names][$loop], $ArrayOfScores[$Scores][$loop]) & @CRLF Next GUICtrlSetData($StatEdit, $temp) GUISetState() ; wait until window is closed Do $msg = GUIGetMsg() Sleep(20) Until $msg = $GUI_EVENT_CLOSE GUIDelete($StatID) EndFunc ;==>DisplayStatHistory There's a little more than the include required, but no biggie. It appears your problem related to using StringFormat(). My mod to your code at least now creates the new file in the format I think you wanted. If you open the reflex.dat file in Scite you can see it as it's processed by your program. At the MsgBox() you can see that it's ok, but after the rewrite (after entering initials) it's trashed. If it was me I'd use a little longer technique like using 2 sections in an ini file. Record the name in 1 and the scores in another. Edit: if you remove the _ArraySort() your score table is written as you want it but with the new score and initials at top. Hope this helps. Edited April 16, 2012 by 4Eyes Link to comment Share on other sites More sharing options...
Valik Posted April 16, 2012 Share Posted April 16, 2012 Thread is fine. We could all do without the lecture on what the report feature is for, though. Link to comment Share on other sites More sharing options...
Topher Posted April 16, 2012 Author Share Posted April 16, 2012 @Eyes You are right. If you remove the sort it works fine (though unsorted). I've written my own sort routine and everything works fine. Thank you. Can't see how one effects the other. Weird. [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left] 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