How would one code a sleep variable to change between 2-3 seconds. As I understand Sleep 2000, sleeps for 2 seconds, how could you randomize the sleep for 1-5 seconds?
![](https://secure.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=100&d=%2F%2Fwww.autohotkey.com%2Fboard%2Fpublic%2Fstyle_images%2Fortem%2Fprofile%2Fdefault_large.png)
Sleep Variable
Started by
Guest 098
, Jun 15 2011 04:16 AM
8 replies to this topic
#1
-
Posted 15 June 2011 - 04:16 AM
![Sleep Variable: post #1](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
#2
-
Posted 15 June 2011 - 04:38 AM
![Sleep Variable: post #2](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
No matter what the random keeps doing Sleep 3000, even when the min is 5000. Here is a sample, it works fine but the random time isnt going at all, it oddly keeps going 3000. I want the other sleeps to be random also but I figure once I get the one working, I can change the rest to match.
MouseClick, left, 1026, 560 Sleep, Random, rand, 5000, 15000 MouseClick, left, 1026, 560 Sleep, 2500 MouseClick, left, 928, 478 Sleep, 2500 MouseClick, left, 1212, 320 Sleep, 2500 MouseClick, left, 1192, 307 Sleep, 2500
#3
-
Posted 15 June 2011 - 05:10 AM
![Sleep Variable: post #3](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
Random, rand, 5000, 15000 ;make rand conatin a random value Sleep, %rand% ;use that random value in the sleep command ;you can't stack commands like you did (that only works for functions) rand(x,y) { ;wrap Random in a function (only needs to be done once in your script) Random, value, %x%, %y% Return value } sleep, % rand(5000,15000) ;use your function to return a random value to your command
#4
-
Posted 15 June 2011 - 05:43 AM
![Sleep Variable: post #4](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
Delay: The amount of time to pause (in milliseconds) between 0 and 2147483647 (24 days), which can be an expression.
Source: <!-- w -->www.autohotkey.com/docs/commands/Sleep.htm<!-- w -->
#5
-
Posted 15 June 2011 - 04:30 PM
![Sleep Variable: post #5](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
can be != must be
It works both ways
I think for new people If you want to put a variable in a command that asks for a string always use %% or force an expression is easier to understand, instead of trying to learn the exceptions.
It works both ways
I think for new people If you want to put a variable in a command that asks for a string always use %% or force an expression is easier to understand, instead of trying to learn the exceptions.
#6
-
Posted 15 June 2011 - 04:45 PM
![Sleep Variable: post #6](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
Fair enough
#7
-
Posted 15 June 2011 - 05:07 PM
![Sleep Variable: post #7](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
I guess I don't quite follow. I keep trying to look at other sample codes I tried two things nether seem right.
rand(x,y) { Random, value, %x%, %y% Return value MouseClick, left, 1026, 560 sleep, % rand(5000,15000) MouseClick, left, 1026, 560 sleep, % rand(5000,15000) MouseClick, left, 928, 478 sleep, % rand(5000,15000) MouseClick, left, 1212, 320 sleep, % rand(5000,15000) MouseClick, left, 1192, 307 sleep, % rand(5000,15000) } or rand(5000,10000) { Random, value, %x%, %y% Return value MouseClick, left, 1026, 560 sleep, % rand MouseClick, left, 1026, 560 sleep, % rand MouseClick, left, 928, 478 sleep, % rand MouseClick, left, 1212, 320 sleep, % rand MouseClick, left, 1192, 307 sleep, % rand }
#8
-
Posted 16 June 2011 - 02:16 AM
![Sleep Variable: post #8](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)
In both of the options you put up you inclued all the code in the function
rand(x,y) { ;start of function Random, value, %x%, %y% Return value } ;end of function MouseClick, left, 1026, 560 sleep, % rand(5000,15000) ;use function MouseClick, left, 1026, 560 sleep, % rand(5000,15000) MouseClick, left, 928, 478 sleep, % rand(5000,15000) MouseClick, left, 1212, 320 sleep, % rand(5000,15000) MouseClick, left, 1192, 307 sleep, % rand(5000,15000)
#9
-
Posted 16 June 2011 - 03:21 AM
![Sleep Variable: post #9](http://www.autohotkey.com/board/public/style_images/ortem/icon_share.png)