Sign in to follow this  
Followers 0
Adergon

[SOLVED] Adding a timer to a loop

19 posts in this topic

#1 ·  Posted (edited)

SOLVED!!!

Edit: Reset the title to something ressembling the original!

Adergon,

Please do not do this again - just add [sOLVED] to the title, not replace it. :)

M23

Edited by Melba23

Share this post


Link to post
Share on other sites



Adergon,

Look at TimerInit and TimerDiff. Then you can code something like this:

$iBegin = TimerInit()

While TimerDiff($iBegin) < whatever_delay_you_want
    Your_Code
WEnd

; You get here when the delay ends

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Adergon,

Look at TimerInit and TimerDiff. Then you can code something like this:

$iBegin = TimerInit()

While TimerDiff($iBegin) < whatever_delay_you_want
    Your_Code
WEnd

; You get here when the delay ends

All clear? :)

M23

This probably works, but i don't know where to put the delay? do you mean like this?

While TimerDiff($iBegin) < 10000

Delay for 10 secs.

Share this post


Link to post
Share on other sites

Adergon,

Have you tried? :)

Yes!

;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Adergon,

Have you tried? ;)

Yes!

:D

M23

$iBegin = TimerInit()
While TimerDiff($iBegin) < 10000
Do
$TestPixel=PixelSearch(302, 26, 817, 359, $PixelTest, 5)
Until Not @error
MouseMove(0,0)
WEnd
MouseMove(15,3)

I tried this, but still, after 10 seconds. it doesnt move on. it still keeps trying to find it :)

EDIT: i added a mousemove and the end too so i know it has moved on:P

Edited by Adergon

Share this post


Link to post
Share on other sites

Adergon,

You need to reverse the comparison if you use a Do...Until loop: :)

$iBegin = TimerInit()
Do
    $TestPixel = PixelSearch(302, 26, 817, 359, $PixelTest, 5)
Until (Not @error) Or TimerDiff($iBegin) > 10000

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Adergon,

You need to reverse the comparison if you use a Do...Until loop: :)

$iBegin = TimerInit()
Do
    $TestPixel = PixelSearch(302, 26, 817, 359, $PixelTest, 5)
Until (Not @error) Or TimerDiff($iBegin) > 10000

M23

Thank you Melba, it worked. But if im right, this command waits 10 seconds, and then finds the color, and stops. But i want it to search for the color, for 10 seconds and then stop if it doesn't find it. and then move on to next function.

ThANks!

Share this post


Link to post
Share on other sites

Adergon,

I am afraid you are wrong! :D

Let us run through the code:

- 1. We set a timestamp with TimerInit.

- 2. We enter a Do loop

- 3. We search for a colour with PixelSearch

- 4. We now check the Until line:

- 4A. If we find the colour @error = 0 so (Not @error) = 1 and we exit the loop (remember that AutoIt treats 0 as False and 1 as True) If we did not find the colour then @error = 1 so (Not @error) = 0 and we move on to check the comparison after the Or....

- 4B. Here we use TimerDiff to see if more than 10secs have elapsed. If they have then we exit the loop - if not then neither part of the Until checks are true and so we loop again.

All clear now? :)

M23

P.S. I would add a Sleep(10) in that loop or your CPU is going to get a bit hot with an almost permanent search. ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Adergon,

I am afraid you are wrong! :D

Let us run through the code:

- 1. We set a timestamp with TimerInit.

- 2. We enter a Do loop

- 3. We search for a colour with PixelSearch

- 4. We now check the Until line:

- 4A. If we find the colour @error = 0 so (Not @error) = 1 and we exit the loop (remember that AutoIt treats 0 as False and 1 as True) If we did not find the colour then @error = 1 so (Not @error) = 0 and we move on to check the comparison after the Or....

- 4B. Here we use TimerDiff to see if more than 10secs have elapsed. If they have then we exit the loop - if not then neither part of the Until checks are true and so we loop again.

All clear now? :)

M23

P.S. I would add a Sleep(10) in that loop or your CPU is going to get a bit hot with an almost permanent search. ;)

Sorry for wasting your time if you need to go, but hmm.. so this code:

$iBegin = TimerInit()
Do
$TestPixel=PixelSearch(302, 26, 817, 359, 0xB9910F, 5)
Until (Not @error) Or TimerDiff($iBegin) > 10000
MouseMove($TestPixel [0], $TestPixel [1])
MouseMove(15,3)

It searches for the color, if it doesn't find it within 10 secs. it exits the loop and moves on to the next function/line. right? but i get an error in this code:

Subscript used with non-Array variable. (Line 17)

Edit: the last mousemove in end is to see if it exits the loops and moves on. ;P

Edited by Adergon

Share this post


Link to post
Share on other sites

Adergon,

You exit the loop on finding the colour or if the timer ran out. In the second case you will not have a valid coordinate array so you need to check if you have an array before trying to use it like this:

$iBegin = TimerInit()
$TestPixel = 0 ; Force the variable NOT to be an array
Do
    $TestPixel = PixelSearch(302, 26, 817, 359, 0xB9910F, 5)
Until (Not @error) Or TimerDiff($iBegin) > 10000
If IsArray($TestPixel) Then ; Check if have a valid array now
    MouseMove($TestPixel[0], $TestPixel[1])
EndIf
MouseMove(15, 3)

Got it? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Adergon,

You exit the loop on finding the colour or if the timer ran out. In the second case you will not have a valid coordinate array so you need to check if you have an array before trying to use it like this:

$iBegin = TimerInit()
$TestPixel = 0 ; Force the variable NOT to be an array
Do
    $TestPixel = PixelSearch(302, 26, 817, 359, 0xB9910F, 5)
Until (Not @error) Or TimerDiff($iBegin) > 10000
If IsArray($TestPixel) Then ; Check if have a valid array now
    MouseMove($TestPixel[0], $TestPixel[1])
EndIf
MouseMove(15, 3)

Got it? :)

M23

Melba is there anyway i can pay you?!?! omg thank you so much!!!! <33 ;):D:D:D

Share this post


Link to post
Share on other sites

Adergon,

Melba is there anyway i can pay you?!?!

You could perhaps donate something to help Jon pay the hosting costs - every little helps. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Adergon,

You could perhaps donate something to help Jon pay the hosting costs - every little helps. :)

M23

I might actually, this is a good website with alot of people helping me in the past months. I will have a look into it ;)

Share this post


Link to post
Share on other sites

close this please.

Share this post


Link to post
Share on other sites

Adergon,

We do not "close" threads - unless you do something we do not like! ;)

If you want to add [solved] or similar to the title, just edit the first post and select the "Use Full Editor" option - that allows you to edit the title as well. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Please do not remove the title and text of the original post when solved! You take away important information for later reference.

All the replies are meaningless without your question!

Add [solved] at beginning of the title - that's all. This tells other users that there is a solution to the problem and might help them solve their own problem.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Title reset to something close to the original. ;)

Adergon,

Please do not do this again - just add [sOLVED] to the title, not replace it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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