Jump to content

How do you use a Timer?


 Share

Recommended Posts

Debugging Output

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Projects\Project - AutoIT\Games & Learning Projects\Slot Machine\timer_breaks.au3" /UserParams    
+>20:17:07 Starting AutoIt3Wrapper v.16.612.1119.0 SciTE v.3.6.6.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Main\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Main\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:D:\Projects\Project - AutoIT\Games & Learning Projects\Slot Machine\timer_breaks.au3
+>20:17:07 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "D:\Projects\Project - AutoIT\Games & Learning Projects\Slot Machine\timer_breaks.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
True
!>20:17:30 AutoIt3.exe ended.rc:-1073741819
+>20:17:30 AutoIt3Wrapper Finished.
>Exit code: 3221225477    Time: 22.84

 

Updated Code

 

#AutoIt3Wrapper_UseX64=y
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Timers.au3>
#include <Debug.au3>

_DebugSetup()

Global $Form1 = GUICreate("Form1", 615, 437, 192, 124)
GUISetState(@SW_SHOW)

Global $myTimer = _Timer_SetTimer($Form1, 1000, "_TimedActivated") ; create timer


Func _TimedActivated($hWnd, $iMsg, $iIDTimer, $iTime)
Dim $Form1, $myTimer
  Local $choice = Random(1,3,1)
    ;ConsoleWrite($choice&@crlf)
    Switch $choice
        Case 1
            ConsoleWrite("case 1"&@crlf)
        Case 2
            ConsoleWrite("case 2"&@crlf)
        Case 3
            $result=_Timer_KillAllTimers ($Form1)
            _DebugReport($result, True)
            consolewrite($result&@crlf)
;~             ConsoleWrite("case 3"&@crlf)
            Exit
    EndSwitch
 EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _Timer_KillAllTimers ($Form1)
            Exit
    EndSwitch
WEnd

 

Attached screen shot of what is shown after Case 3 is run.

 

debugError.jpg

Link to comment
Share on other sites

1 minute ago, Jfish said:

The ticket has been commented with that info.  Workaround for now is to use v 3.3.12

Thanks for helping me track this down as a bug and not anything that I was doing wrong. Will uninstall and reinstall AutoIT with 3.3.12.

Link to comment
Share on other sites

After further investigation I tracked down that this problem with the Timer Kill functions only happens with the full version of Scite which is an optional download from the AutoIT website.  Specifically Scite version 16.612.1119.0

When uninstalling that version of Scite and using the basic version that comes with AutoIT the crashing does not occur in the script in this thread.

Edit:  Updated the ticket Jfish submitted with this updated details.

Edit 2:  I reinstalled 3.3.14.2 and that works as well without the Scite version listed above, with it and CRASH.

Edited by iAmNewbe
Link to comment
Share on other sites

9 hours ago, iAmNewbe said:

I assume that is how it works but I don't see that level of detail in the help documentation. 

I just want a normal timer. starts from 00:00:00 and goes up showing it to the user. I don't think that's what you want.

Anyone can help please? I read the help files, but couldn't find it.

Link to comment
Share on other sites

Alright, apparently from what support is telling me and what I can gather from the manual the Timers set and kill function must be in the same scope physically. Though that is not said any where specifically.

The work around to make a timer stop from within a separate scope like when you set a timer from outside a function and need to kill it from within a function or a separate function when a certain thing happens or doesn't is to use a toggle.

The following code works where the other versions, having Kill Timer functions in a separate scope to the Set Timer caused problems, apparently is the reason 64 bit versions of the script failed with crashing after Timer was killed. Different scopes == DIE HORRIBLY for Timer Kill. 

In this case I create a Toggle that is turned off then turned on when I want the timer to stop.  The While Loop and Timer Set and Kill are all in the same scope the Toggle is in two separate scopes and is checked every run of the loop. I don't personally like that type of code that runs constantly checking for something, but it does work.
 

#AutoIt3Wrapper_UseX64=y
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Timers.au3>

Local $Form1 = GUICreate("Form1", 615, 437, 192, 124)
Global $stopTimer = False
GUISetState(@SW_SHOW)

Global $myTimer = _Timer_SetTimer($Form1, 500, "_TimedActivated") ; create timer

Func _TimedActivated($hWnd, $iMsg, $iIDTimer, $iTime)
Dim $Form1, $myTimer
  Local $choice = Random(1,3,1)
    Switch $choice
        Case 1
            ConsoleWrite("case 1"&@crlf)
        Case 2
            ConsoleWrite("case 2"&@crlf)
        Case 3
            ;~ We run a timer to call this function until Case 3 is activated then we stop timer
            $stopTimer = True; Timer needs to be shutoff or it will keep calling function
            ConsoleWrite("case 3"&@crlf)  ; Needs to display once
            Exit ; exits here only because there is nothing left to do in this particular script, it would stay open forever on it's own.
    EndSwitch
 EndFunc

While 1
   if($stopTimer == True) Then _Timer_KillTimer($Form1, $myTimer) ; Checks if timer is still needed
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _Timer_KillAllTimers ($Form1)
            Exit
    EndSwitch
WEnd

 

Edited by iAmNewbe
Link to comment
Share on other sites

  • Developers
On 10/28/2016 at 11:29 AM, SaeidN said:

I just want a normal timer. starts from 00:00:00 and goes up showing it to the user. I don't think that's what you want.

Anyone can help please? I read the help files, but couldn't find it.

Please stick to your own thread you already have. You have been given pointers so respond there in case things aren't working yet.

Thanks, Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...