AutoHotkey Community

It is currently May 27th, 2012, 1:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: November 29th, 2011, 5:26 pm 
Offline

Joined: November 7th, 2009, 12:01 pm
Posts: 60
The relevant part of my code:

Code:
nSleep = 300

LOAD(2, 3)

LOAD(loops, time) { ;Waits till finished loading page - loops time to wait finish, time to wait before checking
   global nSleep
   sleep, nSleep*%time%
        msgbox, A1
   loop, 100*%loops%
   {
      ImageSearch, LoadX, LoadY, 22,10, 43,31, C:\Users\Loaded.png
      if !errorlevel {
         return
      }
      sleep, nSleep/4
   }
   msgbox, A2
   return
}


What this LOAD function is meant to be doing is pretty much monitoring a little icon in a tab on google chrome, once the icon appears, the page has finished loading. For some reason the msgbox, A2 appears instantly after msgbox, A1.

I know I'm probably calling the variables incorrectly, but I haven't had any trouble calling them in other functions so I'm confused...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2011, 5:58 pm 
Offline

Joined: September 2nd, 2010, 7:47 pm
Posts: 29
Location: Richmond, Indiana USA
Not sure if this is it, but I noticed the text below in the Loop help. Try changing it to
Code:
Load(200, 3)
and
Code:
loop, %loops%


Due to the need to support file-pattern loops, Count cannot be an expression. However, as with all non-expression parameters, an expression can be forcibly used by preceding it with a % and a space. For example: Loop % Count + 1. In such cases, the expression is evaluated only once, right before the loop begins.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2011, 6:06 pm 
Offline

Joined: September 28th, 2007, 3:56 am
Posts: 279
Location: New York
cmikaiti wrote:
Due to the need to support file-pattern loops, Count cannot be an expression. However, as with all non-expression parameters, an expression can be forcibly used by preceding it with a % and a space. For example: Loop % Count + 1. In such cases, the expression is evaluated only once, right before the loop begins.


This text from the help document is correct although. That being said you can change your loop code to look like this

Code:
nSleep = 300

LOAD(2, 3)

LOAD(loops, time) { ;Waits till finished loading page - loops time to wait finish, time to wait before checking
   global nSleep
   sleep, % nSleep*time
        msgbox, A1
   loop, % 100*loops
   {
      ImageSearch, LoadX, LoadY, 22,10, 43,31, C:\Users\Loaded.png
      if !errorlevel {
         return
      }
      sleep, % nSleep/4
   }
   msgbox, A2
   return
}


This forces the arithmetic function to occur before the loop count is read and should fix your problem. I haven't tested it so let me know if you still have issues.

As you can see I used it in your Sleep methods as well. There are many situations where this format can be used and it can make things simpler to write.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2011, 7:52 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Its also good practice to put parentheses around math
Code:
loop, % (100*loops)

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2011, 11:08 am 
Offline

Joined: November 7th, 2009, 12:01 pm
Posts: 60
Thanks a lot guys, it worked wonderfully! :)

I'll be sure to avoid this error in the future. Thanks again.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Amandaville, BrandonHotkey, chaosad, Yahoo [Bot] and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group