Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Sleep Variable


  • Please log in to reply
8 replies to this topic
Guest 098
  • Guests
  • Last active:
  • Joined: --
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?

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
Random you seek Random
read about it and if you can't get it to work post your code for advice.

Guest 098
  • Guests
  • Last active:
  • Joined: --
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



None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
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


nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

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



None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
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.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Fair enough

Guest 098
  • Guests
  • Last active:
  • Joined: --
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

} 



None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
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)