Why won't this section of code Loop? (This is still from the same code btw). If I move the return function outside the }, it errors out, stating a return function is required before the last }.
Code: Select all
#SingleInstance Force
Score:=0
TimeOutCheck:=0
Gui, ReactionTime:New
Gui, Add, Text, x94 y26 w192 h19 vMainText +Center, Are you ready?
Gui, Add, Text, x21 y74 w96 h28 vStarting, Starting in 3...
Gui, Add, Text, x250 y74 w80 vScoreCount, Score : %Score%
Gui, Show, w385 h168, ReactionTime
sleep 1000
GuiControl, ReactionTime:, Starting, Starting in 2.... ;counting down in the start screen
sleep 1000
GuiControl, ReactionTime:, Starting, Starting in 1...
Sleep 1000
GuiControl, Hide, Starting
Gui, New
Gui, Color, Blue
Gui, Add, Button, x40 y45 w144 h67 vRedButton, RED BUTTON
Gui, Show, w236 h159, Blue
Gui, New
Gui, Color, Red
Gui, Add, Button, x40 y45 w144 h67 vBlueButton, BLUE BUTTON
Gui, Show, w236 h159, Red
Loop ; start of the loop
{
sleep 1000
TimeOutCheck:=0
Random, Redx, 0, 1690
Random, Redy, 0, 800
Random, Bluex, 0, 1690
Random, Bluey, 0, 800
Random, RTx, 0, 1400
Random, RTy, 0, 800
WinMove, ReactionTime, , %RTx%, %RTy%
WinMove Red, , %Redx%, %Redy%
WinMove Blue, , %Bluex%, %Bluey%
Random, QuestionType, 1, 4
;MsgBox, random got %QuestionType% `nKey: `n1 = red button `n2 = blue button `n3 = blue button `n4 = red button ; debugging box to see what random got
If (QuestionType = 1)
{
GuiControl, ReactionTime:, MainText, Click the Button Labeled Red Button ; Labled Red Button
}
If (QuestionType = 2)
{
GuiControl, ReactionTime:, MainText, Click the Button in the Red Box ; Button in the red box
}
If (QuestionType = 3)
{
GuiControl, ReactionTime:, MainText, Click the Button Labled Blue Button ; Labled Blue Button
}
If (QuestionType = 4)
{
GuiControl, ReactionTime:, MainText, Click the Button in the Blue Box ; Button in the blue box
}
sleep 5000
If (TimeOutCheck = 0) ; Checking to see if var TimeOutCheck is still 0, if it is, player was too slow and the game ends. If it isn't the following is not run
{
GuiControl, ReactionTime:, MainText, Too SLOW! Game Over...
Gui, Red:Submit, Destory
Gui, Blue:Submit, Destroy
sleep 2000
;run file path goes here
ExitApp
}
return
ButtonREDBUTTON:
{
If (QuestionType = 1)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, Correct!
GuiControl, ReactionTime:, ScoreCount, % "Score : " Score+=1
}
If (QuestionType = 2)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, WRONG! Game Over...
Gui, Red:Submit, Destory
Gui, Blue:Submit, Destroy
sleep 2000
;run file path goes here
ExitApp
}
If (QuestionType = 3)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, WRONG! Game Over...
Gui, Red:Submit, Destory
Gui, Blue:Submit, Destroy
sleep 2000
;run file path goes here
ExitApp
}
If (QuestionType = 4)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, Correct!
GuiControl, ReactionTime:, ScoreCount, % "Score : " Score+=1
}
MsgBox, Gets this far
}
ButtonBLUEBUTTON:
{
If (QuestionType = 1)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, WRONG! Game Over...
Gui, Red:Submit, Destory
Gui, Blue:Submit, Destroy
sleep 2000
;run file path goes here
ExitApp
}
If (QuestionType = 2)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, Correct!
GuiControl, ReactionTime:, ScoreCount, % "Score : " Score+=1
}
If (QuestionType = 3)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, Correct!
GuiControl, ReactionTime:, ScoreCount, % "Score : " Score+=1
}
If (QuestionType = 4)
{
TimeOutCheck:=1
GuiControl, ReactionTime:, MainText, WRONG! Game Over...
Gui, Red:Submit, Destory
Gui, Blue:Submit, Destroy
sleep 2000
;run file path goes here
ExitApp
}
}
return ; It errors out if this return function is not here
}
return
; etc...
It doesn't make any sense, In other scripts, I don't put in a return function before the last } in a loop, but for some reason, it can't run without it??