Sign in to follow this  
Followers 0
Topher

Odd problem

12 posts in this topic

This writes the wrong data to file

Things are fine to the '; _ArrayDisplay($ArrayOfScores)' line, then the array gets scrambled.

help

Func 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]

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by MPH

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

@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]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Topher,

I've had a look see as follows:

#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 by 4Eyes

Share this post


Link to post
Share on other sites

Thread is fine. We could all do without the lecture on what the report feature is for, though.

Share this post


Link to post
Share on other sites

@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]

Share this post


Link to post
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
Sign in to follow this  
Followers 0