Jump to content
Sign in to follow this  
nf67

Func1 prevents any of Func2's actions. (Might be stuck in Func1's loop?)

Recommended Posts

nf67

Hi there,

I have multiple functions in my script, they both should be able to do things at the same time, but they won't.

If you look at the title of this topic and check my code, Func1 is basically the same as TimeLeft and Func2 resembles the actual timer ( $TIMER and $Timeout ) as well as the things $ComboCount and $Streak should be doing. With all commented parts in the script left out, the program works fine and pops up a MsgBox 60 Sec. after 5 is pressed. Also, $Combocount shows you the number your points will be multiplied with, this number increases if you press the right buttons ~15 times in a row without error. But with the ProgressBar function TimeLeft() and it's requirements ( like a GUI ProgressBar) in the script, these things don't work anymore... I think the script gets "stuck" in the TimeLeft() loop and doesn't get to the other things but I'm not completely sure.

Please help,

Here's my code: (all parts that have something to do with the ProgressBar, like TimeLeft() are commented ;

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Include <Timers.au3>
#include <ProgressConstants.au3>


Global $TIMER = TimerInit()
Global $LAST = Random(1,4,1)
Global $Points = 0
Global $Streak = 0
Global $Sound = 1
Global Const $TIMEOUT = 60000
Global $Looper = 1



$Slothor = GUICreate("Slothor", 173, 235, 192, 114)
GUISetBkColor(0x343434, $Slothor)
$Commander = GUICtrlCreateEdit("GO 5"&@crlf, 5, 10, 160, 120, BitOR($ES_CENTER,$ES_AUTOVSCROLL,$ES_WANTRETURN,$ES_READONLY,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 37, 800, 0, "Arial")
$Button1 = GUICtrlCreateButton("1", 5, 128, 40, 60)
GUICtrlSetBkColor(-1, 0x204383)
GUICtrlSetState ($Button1, $GUI_DISABLE)
$Button2 = GUICtrlCreateButton("2", 45, 128, 40, 60)
GUICtrlSetBkColor(-1, 0x918A39)
GUICtrlSetState ($Button2, $GUI_DISABLE)
$Button3 = GUICtrlCreateButton("3", 85, 128, 40, 60)
GUICtrlSetBkColor(-1, 0x7B1314)
GUICtrlSetState ($Button3, $GUI_DISABLE)
$Button4 = GUICtrlCreateButton("4", 125, 128, 40, 60)
GUICtrlSetBkColor(-1, 0x196C38)
GUICtrlSetState ($Button4, $GUI_DISABLE)
$Score = GUICtrlCreateEdit("Score", 5, 184, 140, 25, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_WANTRETURN,$ES_READONLY))
GUICtrlSetFont(-1, 12, 800, 2, "Arial")
$Combocount = GUICtrlCreateEdit("C", 145, 184, 20, 25, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_WANTRETURN,$ES_READONLY))
GUICtrlSetFont(-1, 12, 800, 2, "Arial")
$Timetrack = GUICtrlCreateProgress(5, 208, 140, 20, $PBS_SMOOTH); <--------------------------------ProgressBar
$S = GUICtrlCreateButton("S", 145, 208, 20, 20)
GUISetState(@SW_SHOW)
ControlFocus ( "Slothor", "", $Button1)



HotKeySet ("5", "Go")
Func Go()
    GUICtrlSetState ($Button1, $GUI_ENABLE)
    GUICtrlSetState ($Button2, $GUI_ENABLE)
    GUICtrlSetState ($Button3, $GUI_ENABLE)
    GUICtrlSetState ($Button4, $GUI_ENABLE)
    _Timer_KillTimer($Slothor, $TIMER)
    $TIMER = TimerInit()
    $LAST = Random(1,4,1)
    $Points = 0
    $Streak = 0
    GUICtrlSetData ($Score, $Points)
    GUICtrlSetData($Commander, $LAST&@crlf, 1)
    GUICtrlSetData($Timetrack,100);Set ProgressBar to full  
    TimeLeft();Start ProgressBar! (See below for func)
EndFunc

Func Timeleft()
    $TimeValue = 100;Set the timevalue
    Do;Repeat until the time is up
        Sleep (1000);After every second
        $TimeValue = $TimeValue - (100/60); Timevalue is decreased by 100/60 
        GuiCtrlSetData($Timetrack, $TimeValue);And the progressbar is set to the timevalue
    Until $TimeValue = 0  ; Until there is no more time left
EndFunc
    

HotKeySet ("1", "Press1") 
Func Press1()
            If $LAST = 1 Then
            $Streak = $Streak+1
                if $Streak > 0 then
                $Points = $Points+25
                endif
                if $Streak > 15 then
                $Points = $Points+25
                endif
                if $Streak > 35 then
                $Points = $Points+25
                endif
                if $Streak > 55 then
                $Points = $Points+25
                endif
                if $Streak > 70 then
                $Points = $Points+25
                endif
                if $Streak > 95 then
                $Points = $Points+25
                endif
            GUICtrlSetData ($Score, $Points)         
                If $Sound = 1 Then
                Beep (600, 50)
                Else
                Sleep (50)  
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            else 
            $Points = $Points-50
            $Streak = $Streak-$Streak
            GUICtrlSetData ($Score, $Points) 
            GUICtrlSetData($Commander, "(-.-)"&@crlf, 1)
                if $Sound = 1 Then
                Beep ( 100, 1500 )
                else
                Sleep (1500)
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            EndIf
EndFunc

HotKeySet ("2", "Press2") 
Func Press2()
            If $LAST = 2 Then
            $Streak = $Streak+1
                if $Streak > 0 then
                $Points = $Points+25
                endif
                if $Streak > 15 then
                $Points = $Points+25
                endif
                if $Streak > 35 then
                $Points = $Points+25
                endif
                if $Streak > 55 then
                $Points = $Points+25
                endif
                if $Streak > 70 then
                $Points = $Points+25
                endif
                if $Streak > 95 then
                $Points = $Points+25
                endif
                if $Streak > 0 then
                $Points = $Points+25
                endif
            GUICtrlSetData ($Score, $Points)
                If $Sound = 1 Then
                Beep (500, 50)
                Else
                Sleep (50)        
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            else 
            $Points = $Points-50
            $Streak = $Streak-$Streak
            GUICtrlSetData ($Score, $Points)
            GUICtrlSetData($Commander, "(-.-)"&@crlf, 1)
                if $Sound = 1 Then
                Beep ( 100, 1500 )
                else
                Sleep (1500)
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            EndIf
EndFunc

HotKeySet ("3", "Press3") 
Func Press3()
            If $LAST = 3 Then
            $Streak = $Streak+1
                if $Streak > 0 then
                $Points = $Points+25
                endif
                if $Streak > 15 then
                $Points = $Points+25
                endif
                if $Streak > 35 then
                $Points = $Points+25
                endif
                if $Streak > 55 then
                $Points = $Points+25
                endif
                if $Streak > 70 then
                $Points = $Points+25
                endif
                if $Streak > 95 then
                $Points = $Points+25
                endif
            GUICtrlSetData ($Score, $Points)
                If $Sound = 1 Then
                Beep (400, 50)
                Else
                Sleep (50)
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            else 
            $Points = $Points-50
            $Streak = $Streak-$Streak
            GUICtrlSetData ($Score, $Points)
            GUICtrlSetData($Commander, "(-.-)"&@crlf, 1)
                if $Sound = 1 Then
                Beep ( 100, 1500 )
                else
                Sleep (1500)
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            EndIf
EndFunc
        
HotKeySet ("4", "Press4") 
Func Press4()
            If $LAST = 4 Then
            $Streak = $Streak+1
                if $Streak > 0 then
                $Points = $Points+25
                endif
                if $Streak > 15 then
                $Points = $Points+25
                endif
                if $Streak > 35 then
                $Points = $Points+25
                endif
                if $Streak > 55 then
                $Points = $Points+25
                endif
                if $Streak > 70 then
                $Points = $Points+25
                endif
                if $Streak > 95 then
                $Points = $Points+25
                endif
            GUICtrlSetData ($Score, $Points)
                If $Sound = 1 Then
                Beep (300, 50)
                Else
                Sleep (50)
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            else 
            $Points = $Points-50
            $Streak = $Streak-$Streak
            GUICtrlSetData ($Score, $Points)
            GUICtrlSetData($Commander, "(-.-)"&@crlf, 1)
                if $Sound = 1 Then
                Beep ( 100, 1500 )
                else
                Sleep (1500)
                Endif
            $LAST = Random(1,4,1)
            GUICtrlSetData($Commander, $LAST&@crlf, 1)
            EndIf
EndFunc

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Button1
            Press1()
                        
        Case $Button2
            Press2()
        
        Case $Button3
            Press3()
        
        Case $Button4
            Press4()
        
        Case $S
            if $Sound = 0 Then
            $Sound = 1
            else
            $Sound = 0
            Endif
 
    EndSwitch
    
    If $Streak = 0 Then
    GUICtrlSetData ($Combocount, "1")
    EndIf   

    If $Streak = 15 Then
    GUICtrlSetData ($Combocount, "2")
    EndIf   

    If $Streak = 35 Then
    GUICtrlSetData ($Combocount, "3")
    EndIf   
    
    If $Streak = 55 Then
    GUICtrlSetData ($Combocount, "4")
    EndIf   

    If $Streak = 70 Then
    GUICtrlSetData ($Combocount, "5")
    EndIf   

    If TimerDiff($TIMER) > $TIMEOUT Then
    FileWrite(@ScriptDir & "\Scores.txt", $Points&@CRLF)
    $Last = 0
    $RetryAnswer = MsgBox(36, "Game Over", "You scored "&$Points &" points. Retry?", 5000)
        Select
            Case $RetryAnswer = 6
GUICtrlSetState ($Button1, $GUI_DISABLE)
GUICtrlSetState ($Button2, $GUI_DISABLE)
GUICtrlSetState ($Button3, $GUI_DISABLE)
GUICtrlSetState ($Button4, $GUI_DISABLE)
_Timer_KillTimer($Slothor, $TIMER)
$TIMER = TimerInit()
GUICtrlSetData($Commander, "GO 5"&@crlf, 1)
            Case $RetryAnswer = 7 
            WinKill ( "Game Over" )
            GUISetState(@SW_HIDE, $Slothor)
                $Scores = FileRead(@ScriptDir & "\Scores.txt")
                $Highscores = GUICreate("Highscores", 163, 58, 193, 115)
                $ScoreView = GUICtrlCreateEdit("Scores:"&@CRLF & $Scores, 0, 0, 161, 57, BitOR($ES_WANTRETURN,$WS_VSCROLL,$ES_READONLY))
                GUISetState(@SW_SHOW)
                        While 3
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                WinKill ("Slothor")
                                ExitLoop
                            EndSelect
                        WEnd
        EndSelect
    EndIf
WEnd

Thanks, :P

Edited by nf67

Share this post


Link to post
Share on other sites
martin

Too much for me to read, but if you believe your script, or any script, can execute more than one function at a time then things are bound to fail.

The function for the progress bar should not have a do/while loop in it so that nothing else can be done while the progress bar is updated.

Remove

$Timer = TimerInit()

near the start of your script.

Change the lines from HotKeySet to the end of the Timer function for something like this.

HotKeySet("5", "Go")
Func Go()
    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUICtrlSetState($Button2, $GUI_ENABLE)
    GUICtrlSetState($Button3, $GUI_ENABLE)
    GUICtrlSetState($Button4, $GUI_ENABLE)
;;_Timer_KillTimer($Slothor, $TIMER); no, if $Timer is the value returned by TimerInit it is not a timer it is an integer.

    $LAST = Random(1, 4, 1)
    $Points = 0
    $Streak = 0
    GUICtrlSetData($Score, $Points)
    GUICtrlSetData($Commander, $LAST & @CRLF, 1)
    GUICtrlSetData($Timetrack, 100);Set ProgressBar to full
    $TimeValue = 100;Set the timevalue . Do that here not in th eTimeleft fn
    $Timer = _Timer_SetTimer($Slothor, 1000, "TimeLeft")
EndFunc  ;==>Go

Func Timeleft($a,$b,$c,$d);unused parameters but timer functions must have parameters!

    $TimeValue = $TimeValue - (100 / 60); Timevalue is decreased by 100/60
    GUICtrlSetData($Timetrack, $TimeValue);And the progressbar is set to the timevalue
    If $TimeValue <= 0 Then
        _Timer_KillTimer($Slothor, $Timer);
    EndIf
EndFunc  ;==>Timeleft

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
nf67

HotKeySet ("5", "Go")
Func Go()
    GUICtrlSetState ($Button1, $GUI_ENABLE)
    GUICtrlSetState ($Button2, $GUI_ENABLE)
    GUICtrlSetState ($Button3, $GUI_ENABLE)
    GUICtrlSetState ($Button4, $GUI_ENABLE)
    $TimeValue = 100;Set the timevalue    <-----------You said to put that here
    $Timer = _Timer_SetTimer($Slothor, 1000, "TimeLeft")
    $LAST = Random(1,4,1)
    $Points = 0
    $Streak = 0
    GUICtrlSetData ($Score, $Points)
    GUICtrlSetData($Commander, $LAST&@crlf, 1)
    GUICtrlSetData($Timetrack,100)  
    TimeLeft()
EndFunc

Func Timeleft($a,$b,$c,$d)
    $TimeValue = $TimeValue - (100 / 60)
    GUICtrlSetData($Timetrack, $TimeValue)
    If $TimeValue <= 0 Then
        _Timer_KillTimer($Slothor, $Timer);
    EndIf
EndFunc

Returns WARNING: $TimeValue: possibly used before declaration.

Full error log:

C:\Documents and Settings\Chris\Mijn documenten\Beep\beep.au3(69,88) : ERROR: TimeLeft() called by a previous line with 0 arg(s). Min = 4. First previous line calling this Func is 64.

Func Timeleft($a,$b,$c,$d);unused parameters but timer functions must have parameters!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Chris\Mijn documenten\Beep\beep.au3(70,26) : WARNING: $TimeValue: possibly used before declaration.

$TimeValue = $TimeValue -

~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Chris\Mijn documenten\Beep\beep.au3 - 1 error(s), 1 warning(s)

Can you please try to implent your script in the full code? Because I don't really get it :P

Too much for me to read, but if you believe your script, or any script, can execute more than one function at a time then things are bound to fail

As for this, I might have "mis-used" the term Func a bit, I actually mean the normal actiosn performed by the script, like the ComboCount and MsgBox if out of time. Explained that in my first post as well :( .

Edited by nf67

Share this post


Link to post
Share on other sites
martin

I have no idea what the idea of your game is so although the script below does seem to do something, it probably is not what it's supposed to.

Maybe it's enough to get you going.

CODE

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <GUIConstants.au3>

#include <WindowsConstants.au3>

#include <Constants.au3>

#include <Timers.au3>

#include <ProgressConstants.au3>

Global $TIMER, $TimeValue = 100; = TimerInit()

Global $LAST = Random(1, 4, 1)

Global $Points = 0

Global $Streak = 0

Global $Sound = 1

Global Const $TIMEOUT = 60000

Global $Looper = 1

$Slothor = GUICreate("Slothor", 173, 235, 192, 114)

GUISetBkColor(0x343434, $Slothor)

$Commander = GUICtrlCreateEdit("GO 5" & @CRLF, 5, 10, 160, 120, BitOR($ES_CENTER, $ES_AUTOVSCROLL, $ES_WANTRETURN, $ES_READONLY, $ES_AUTOHSCROLL))

GUICtrlSetFont(-1, 37, 800, 0, "Arial")

$Button1 = GUICtrlCreateButton("1", 5, 128, 40, 60)

GUICtrlSetBkColor(-1, 0x204383)

GUICtrlSetState($Button1, $GUI_DISABLE)

$Button2 = GUICtrlCreateButton("2", 45, 128, 40, 60)

GUICtrlSetBkColor(-1, 0x918A39)

GUICtrlSetState($Button2, $GUI_DISABLE)

$Button3 = GUICtrlCreateButton("3", 85, 128, 40, 60)

GUICtrlSetBkColor(-1, 0x7B1314)

GUICtrlSetState($Button3, $GUI_DISABLE)

$Button4 = GUICtrlCreateButton("4", 125, 128, 40, 60)

GUICtrlSetBkColor(-1, 0x196C38)

GUICtrlSetState($Button4, $GUI_DISABLE)

$Score = GUICtrlCreateEdit("Score", 5, 184, 140, 25, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_WANTRETURN, $ES_READONLY))

GUICtrlSetFont(-1, 12, 800, 2, "Arial")

$Combocount = GUICtrlCreateEdit("C", 145, 184, 20, 25, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_WANTRETURN, $ES_READONLY))

GUICtrlSetFont(-1, 12, 800, 2, "Arial")

$Timetrack = GUICtrlCreateProgress(5, 208, 140, 20, $PBS_SMOOTH); <--------------------------------ProgressBar

$S = GUICtrlCreateButton("S", 145, 208, 20, 20)

GUISetState(@SW_SHOW)

ControlFocus("Slothor", "", $Button1)

#cs

HotKeySet ("5", "Go")

Func Go()

GUICtrlSetState ($Button1, $GUI_ENABLE)

GUICtrlSetState ($Button2, $GUI_ENABLE)

GUICtrlSetState ($Button3, $GUI_ENABLE)

GUICtrlSetState ($Button4, $GUI_ENABLE)

_Timer_KillTimer($Slothor, $TIMER)

$TIMER = TimerInit()

$LAST = Random(1,4,1)

$Points = 0

$Streak = 0

GUICtrlSetData ($Score, $Points)

GUICtrlSetData($Commander, $LAST&@crlf, 1)

GUICtrlSetData($Timetrack,100);Set ProgressBar to full

TimeLeft();Start ProgressBar! (See below for func)

EndFunc

Func Timeleft()

$TimeValue = 100;Set the timevalue

Do;Repeat until the time is up

Sleep (1000);After every second

$TimeValue = $TimeValue - (100/60); Timevalue is decreased by 100/60

GuiCtrlSetData($Timetrack, $TimeValue);And the progressbar is set to the timevalue

Until $TimeValue = 0 ; Until there is no more time left

EndFunc

#ce

HotKeySet("5", "Go")

Func Go()

GUICtrlSetState($Button1, $GUI_ENABLE)

GUICtrlSetState($Button2, $GUI_ENABLE)

GUICtrlSetState($Button3, $GUI_ENABLE)

GUICtrlSetState($Button4, $GUI_ENABLE)

$LAST = Random(1, 4, 1)

$Points = 0

$Streak = 0

GUICtrlSetData($Score, $Points)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

GUICtrlSetData($Timetrack, 100);Set ProgressBar to full

$TimeValue = 100;Set the timevalue . Do that here not in th eTimeleft fn

$TIMER = _Timer_SetTimer($Slothor, 1000, "TimeLeft")

EndFunc ;==>Go

Func Timeleft($a, $b, $c, $d);unused parameters but timer functions must have parameters!

$TimeValue = $TimeValue - (100 / 60); Timevalue is decreased by 100/60

ConsoleWrite($TimeValue & @CRLF)

GUICtrlSetData($Timetrack, $TimeValue);And the progressbar is set to the timevalue

If $TimeValue <= 0 Then

_Timer_KillTimer($Slothor, $TIMER);

EndIf

EndFunc ;==>Timeleft

HotKeySet("1", "Press1")

Func Press1()

If $LAST = 1 Then

$Streak = $Streak + 1

If $Streak > 0 Then

$Points = $Points + 25

EndIf

If $Streak > 15 Then

$Points = $Points + 25

EndIf

If $Streak > 35 Then

$Points = $Points + 25

EndIf

If $Streak > 55 Then

$Points = $Points + 25

EndIf

If $Streak > 70 Then

$Points = $Points + 25

EndIf

If $Streak > 95 Then

$Points = $Points + 25

EndIf

GUICtrlSetData($Score, $Points)

If $Sound = 1 Then

Beep(600, 50)

Else

Sleep(50)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

Else

$Points = $Points - 50

$Streak = $Streak - $Streak

GUICtrlSetData($Score, $Points)

GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1)

If $Sound = 1 Then

Beep(100, 1500)

Else

Sleep(1500)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

EndIf

EndFunc ;==>Press1

HotKeySet("2", "Press2")

Func Press2()

If $LAST = 2 Then

$Streak = $Streak + 1

If $Streak > 0 Then

$Points = $Points + 25

EndIf

If $Streak > 15 Then

$Points = $Points + 25

EndIf

If $Streak > 35 Then

$Points = $Points + 25

EndIf

If $Streak > 55 Then

$Points = $Points + 25

EndIf

If $Streak > 70 Then

$Points = $Points + 25

EndIf

If $Streak > 95 Then

$Points = $Points + 25

EndIf

If $Streak > 0 Then

$Points = $Points + 25

EndIf

GUICtrlSetData($Score, $Points)

If $Sound = 1 Then

Beep(500, 50)

Else

Sleep(50)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

Else

$Points = $Points - 50

$Streak = $Streak - $Streak

GUICtrlSetData($Score, $Points)

GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1)

If $Sound = 1 Then

Beep(100, 1500)

Else

Sleep(1500)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

EndIf

EndFunc ;==>Press2

HotKeySet("3", "Press3")

Func Press3()

If $LAST = 3 Then

$Streak = $Streak + 1

If $Streak > 0 Then

$Points = $Points + 25

EndIf

If $Streak > 15 Then

$Points = $Points + 25

EndIf

If $Streak > 35 Then

$Points = $Points + 25

EndIf

If $Streak > 55 Then

$Points = $Points + 25

EndIf

If $Streak > 70 Then

$Points = $Points + 25

EndIf

If $Streak > 95 Then

$Points = $Points + 25

EndIf

GUICtrlSetData($Score, $Points)

If $Sound = 1 Then

Beep(400, 50)

Else

Sleep(50)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

Else

$Points = $Points - 50

$Streak = $Streak - $Streak

GUICtrlSetData($Score, $Points)

GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1)

If $Sound = 1 Then

Beep(100, 1500)

Else

Sleep(1500)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

EndIf

EndFunc ;==>Press3

HotKeySet("4", "Press4")

Func Press4()

If $LAST = 4 Then

$Streak = $Streak + 1

If $Streak > 0 Then

$Points = $Points + 25

EndIf

If $Streak > 15 Then

$Points = $Points + 25

EndIf

If $Streak > 35 Then

$Points = $Points + 25

EndIf

If $Streak > 55 Then

$Points = $Points + 25

EndIf

If $Streak > 70 Then

$Points = $Points + 25

EndIf

If $Streak > 95 Then

$Points = $Points + 25

EndIf

GUICtrlSetData($Score, $Points)

If $Sound = 1 Then

Beep(300, 50)

Else

Sleep(50)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

Else

$Points = $Points - 50

$Streak = $Streak - $Streak

GUICtrlSetData($Score, $Points)

GUICtrlSetData($Commander, "(-.-)" & @CRLF, 1)

If $Sound = 1 Then

Beep(100, 1500)

Else

Sleep(1500)

EndIf

$LAST = Random(1, 4, 1)

GUICtrlSetData($Commander, $LAST & @CRLF, 1)

EndIf

EndFunc ;==>Press4

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

Press1()

Case $Button2

Press2()

Case $Button3

Press3()

Case $Button4

Press4()

Case $S

If $Sound = 0 Then

$Sound = 1

Else

$Sound = 0

EndIf

EndSwitch

If $Streak = 0 Then

GUICtrlSetData($Combocount, "1")

EndIf

If $Streak = 15 Then

GUICtrlSetData($Combocount, "2")

EndIf

If $Streak = 35 Then

GUICtrlSetData($Combocount, "3")

EndIf

If $Streak = 55 Then

GUICtrlSetData($Combocount, "4")

EndIf

If $Streak = 70 Then

GUICtrlSetData($Combocount, "5")

EndIf

If $Timevalue <= 0 then; $TIMEOUT Then

FileWrite(@ScriptDir & "\Scores.txt", $Points & @CRLF)

$LAST = 0

$RetryAnswer = MsgBox(36, "Game Over", "You scored " & $Points & " points. Retry?", 5000)

Select

Case $RetryAnswer = 6

GUICtrlSetState($Button1, $GUI_DISABLE)

GUICtrlSetState($Button2, $GUI_DISABLE)

GUICtrlSetState($Button3, $GUI_DISABLE)

GUICtrlSetState($Button4, $GUI_DISABLE)

;_Timer_KillTimer($Slothor, $TIMER)

;$TIMER = TimerInit()

GUICtrlSetData($Commander, "GO 5" & @CRLF, 1)

Case $RetryAnswer = 7

WinKill("Game Over")

GUISetState(@SW_HIDE, $Slothor)

$Scores = FileRead(@ScriptDir & "\Scores.txt")

$Highscores = GUICreate("Highscores", 163, 58, 193, 115)

$ScoreView = GUICtrlCreateEdit("Scores:" & @CRLF & $Scores, 0, 0, 161, 57, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_READONLY))

GUISetState(@SW_SHOW)

While 3

$msg3 = GUIGetMsg()

Select

Case $msg3 = $GUI_EVENT_CLOSE

WinKill("Slothor")

ExitLoop

EndSelect

WEnd

EndSelect

EndIf

WEnd


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
nf67

It sure is what it's supposed to do. I added a $TimeValue = 100 at the bottom to "untrue" the

If $Timevalue <= 0 then; $TIMEOUT Then

statement, it kept popping up the "Game over" MsgBox :P

Thanks a lot for your help

Edited by nf67

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.