Jump to content

GUI Problems


Recommended Posts

Here is my script. It is a score tracker for video games. My problems are: After opening one of the games, or adding a new score, or doing anything, the GUI becomes unresponsive. Also, when the Close button on one of the games is clicked, the whole program exits. I just want the game window to exit, and in my other programs GUIDelete works for this, but for some reason in this it doesn't. Anyone know why this is happening and/or how I can fix it?

CODE
#include <array.au3>

#include <GUIConstants.au3>

AutoItSetOption("TrayAutoPause", 0)

$g1s = _ArrayCreate(0, 0, 0, 0, 0)

$g1s[0] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 1", 0)

$g1s[1] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 2", 0)

$g1s[2] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 3", 0)

$g1s[3] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 4", 0)

$g1s[4] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 5", 0)

_ArraySort($g1s, 1)

$g2s = _ArrayCreate(0, 0, 0, 0, 0)

$g2s[0] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 1", 0)

$g2s[1] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 2", 0)

$g2s[2] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 3", 0)

$g2s[3] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 4", 0)

$g2s[4] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 5", 0)

_ArraySort($g2s, 1)

$g3s = _ArrayCreate(0, 0, 0, 0, 0)

$g3s[0] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 1", 0)

$g3s[1] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 2", 0)

$g3s[2] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 3", 0)

$g3s[3] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 4", 0)

$g3s[4] = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 5", 0)

_ArraySort($g3s, 1)

DirCreate(@ScriptDir & "\ScoreBoard Data")

GUICreate("Score Board", 200, 200)

$g1n = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game Names", "Game 1", "Game Name")

$g2n = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game Names", "Game 2", "Game Name")

$g3n = IniRead(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game Names", "Game 3", "Game Name")

$ov = GUICtrlCreateButton("Overall Highs", 110, 10)

$g1 = GUICtrlCreateButton($g1n, 10, 10)

$g2 = GUICtrlCreateButton($g2n, 10, 40)

$g3 = GUICtrlCreateButton($g3n, 10, 70)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg ()

Select

Case $msg = $ov

MsgBox(0, "Game High Scores", $g1n & " High Score is " & $g1s[0] & ", " & $g2n & " High Score is " & $g2s[0] & ", and " & $g3n & " High Score is " & $g3s[0] & ".")

Case $msg = $g1

If $g1n = "Game Name" Then

$g1ns = InputBox("Name the Game", "Enter the name of this game.")

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game Names", "Game 1", $g1ns)

Else

$me = GUICreate($g1n, 200, 200)

$g1hs = _ArrayMax($g1s)

GUICtrlCreateLabel($g1n & " High Score is: " & $g1hs, 10, 10)

$gethsong1 = GUICtrlCreateButton("High Score List", 10, 40)

$adnewsg1 = GUICtrlCreateButton("Add new...", 10, 70)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg ()

Select

Case $msg = $gethsong1

_ArrayDisplay($g1s, $g1n & " High Scores")

Case $msg = $GUI_EVENT_CLOSE

GUIDelete ()

Case $msg = $adnewsg1

$newsx = InputBox("New Score", "Enter your new score.")

If StringIsAlNum($newsx) = 1 Then

$news = $newsx

_ArrayAdd($g1s, $news)

_ArraySort($g1s, 1)

_ArrayPop($g1s)

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 1", $g1s[0])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 2", $g1s[1])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 3", $g1s[2])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 4", $g1s[3])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 1 Scores", "Game 1 score 5", $g1s[4])

Else

MsgBox(0, "Sorry", "Only numbers are accepted in that field.")

EndIf

ExitLoop

EndSelect

WEnd

EndIf

Case $msg = $g2

If $g2n = "Game Name" Then

$g2ns = InputBox("Name the Game", "Enter the name of this game.")

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game Names", "Game 2", $g2ns)

Else

$me2 = GUICreate($g2n, 200, 200)

$g2hs = _ArrayMax($g2s)

GUICtrlCreateLabel($g2n & " High Score is: " & $g2hs, 10, 10)

$gethsong2 = GUICtrlCreateButton("High Score List", 10, 40)

$adnewsg2 = GUICtrlCreateButton("Add new...", 10, 70)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg ()

Select

Case $msg = $gethsong2

_ArrayDisplay($g2s, $g2n & " High Scores")

Case $msg = $GUI_EVENT_CLOSE

GUIDelete ()

Case $msg = $adnewsg2

$newsx = InputBox("New Score", "Enter your new score.")

If StringIsAlNum($newsx) = 1 Then

$news = $newsx

_ArrayAdd($g2s, $news)

_ArraySort($g2s, 1)

_ArrayPop($g2s)

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 1", $g2s[0])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 2", $g2s[1])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 3", $g2s[2])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 4", $g2s[3])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 2 Scores", "Game 2 score 5", $g2s[4])

Else

MsgBox(0, "Sorry", "Only numbers are accepted in that field.")

EndIf

ExitLoop

EndSelect

WEnd

EndIf

Case $msg = $g3

If $g3n = "Game Name" Then

$g3ns = InputBox("Name the Game", "Enter the name of this game.")

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game Names", "Game 3", $g3ns)

Else

$me3 = GUICreate($g3n, 200, 200)

$g3hs = _ArrayMax($g3s)

GUICtrlCreateLabel($g3n & " High Score is: " & $g3hs, 10, 10)

$gethsong3 = GUICtrlCreateButton("High Score List", 10, 40)

$adnewsg3 = GUICtrlCreateButton("Add new...", 10, 70)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg ()

Select

Case $msg = $gethsong3

_ArrayDisplay($g3s, $g3n & " High Scores")

Case $msg = $GUI_EVENT_CLOSE

GUIDelete ()

Case $msg = $adnewsg3

$newsx = InputBox("New Score", "Enter your new score.")

If StringIsAlNum($newsx) = 1 Then

$news = $newsx

_ArrayAdd($g3s, $news)

_ArraySort($g3s, 1)

_ArrayPop($g3s)

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 1", $g3s[0])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 2", $g3s[1])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 3", $g3s[2])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 4", $g3s[3])

IniWrite(@ScriptDir & "\ScoreBoard Data\ScoreBoard Data.ini", "Game 3 Scores", "Game 3 score 5", $g3s[4])

Else

MsgBox(0, "Sorry", "Only numbers are accepted in that field.")

EndIf

ExitLoop

EndSelect

WEnd

EndIf

Case $msg = $GUI_EVENT_CLOSE

Exit

ExitLoop

EndSelect

WEnd

Link to comment
Share on other sites

Does anyone know how to solve the other problem (GUI becomes unresponsive)?

You need

$msg = GuiGetMsg(1) ; advanced mode

Look here for example

Link to comment
Share on other sites

It's happening again with another GUI! This is driving me nuts! :)

Does anyone know how to solve the other problem (GUI becomes unresponsive)?

Link to comment
Share on other sites

It's happening again with another GUI! This is driving me nuts! :)

You have a GuiGetMsg() loop inside your GuiGetMsg() loop. Once it enters the inner loop (second GUI), it is not testing Case's for the controls on the outer one any more. You need a single loop that can handle all the $msg values from all the possible GUIs. Remember it won't hurt to have Case's for controls that don't exist at the moment, but will be there to handle them when they do.

Another option that would involve more re-write would be to change the whole thing over to GuiOnEventMode.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...