Possible to change all sleep timings?

Get help with using AutoHotkey and its commands and hotkeys
ZanderM_

Possible to change all sleep timings?

02 Sep 2016, 02:18

Hi,

I have a script With containing a couple hundred sleep funcitons.

I was wondering if anyone knows a simple and smart way to change all those timings easily on the go?

I'll draft out an example of what I want to be able to do:

Let's say I have a checkbox, where the user can check it for superspeed, and uncheck it for slower speed.
When the checkbox is checked, I want to divide all sleep timings by 2.

Anyone knows how to do this, or maybe someone has a better way of creating something similar?
aaffe
Posts: 158
Joined: 16 Jan 2014, 04:23

Re: Possible to change all sleep timings?

02 Sep 2016, 02:32

Code: Select all

checked:=0
sleeptime:=2000

If (checked)
	sleeptime/=2

msgbox %sleeptime%
sleep,%sleeptime%

checked:=1
If (checked)
	sleeptime/=2

msgbox %sleeptime%
sleep,%sleeptime%
User avatar
Blackholyman
Posts: 1292
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Possible to change all sleep timings?

02 Sep 2016, 02:36

change your sleep amounts to a variable then you can use a gui to change the size of all the sleeps in one place, or if you have many sleep sizes the have the number to divide by as a variable

Code: Select all

sleep_amout := 1000
divider := 2

sleep, sleep_amout ; sleeps 1000
sleep, sleep_amout/divider ; sleeps 500
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
zanderM
Posts: 3
Joined: 02 Jun 2016, 03:10

Re: Possible to change all sleep timings?

02 Sep 2016, 02:48

I've thought of that, but it's a really time consuming Method, I mean, creating 200 variables...
zanderM
Posts: 3
Joined: 02 Jun 2016, 03:10

Re: Possible to change all sleep timings?

02 Sep 2016, 02:54

I should maybe add something, I think it would open up for more solutions.

It doesn't have to change "on the go" as I wrote, but would it maybe be possible to create an external script that parses through the main script, then dividing or multiplying every sleep function?

simple pseudo example:
parse main script line by line
if line contains "sleep "
loop parse line
if x is number
divide x by 2
User avatar
Blackholyman
Posts: 1292
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Possible to change all sleep timings?

02 Sep 2016, 03:09

why not change them to variables instead of dividing the number?

variables gives you way more rum for improving your functionality overtime

and why do you need 200 variables? simply use expressions so you variant them using math

Code: Select all

sleep_amout := 1000


sleep, sleep_amout ; sleeps 1000
sleep, sleep_amout/2 ; sleeps 500
sleep, sleep_amout*3 ; sleeps 3000
sleep, sleep_amout*10 ; sleeps 10000
sleep, sleep_amout/3.3 ; sleeps 303.03
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
zanderM
Posts: 3
Joined: 02 Jun 2016, 03:10

Re: Possible to change all sleep timings?

02 Sep 2016, 03:25

That would take even longer considering I have pretty specific timings, but would be easier to manage I Guess..

Thing is, I have very small, specific and different timings..

example:

sleep 30
sleep 40
sleep 60
sleep 90
sleep 100
sleep 135
sleep 175
sleep 200
sleep 225
...
...
sleep 4100
sleep 4250

would be:

sleep_amout := 1000
sleep, sleep_amout/30.3333333333
sleep, sleep_amout/25
sleep, sleep_amout/16.6666666666
sleep, sleep_amout/11.1111111111
sleep, sleep_amout/10
sleep, sleep_amout/7.40740740740

....
...
...



Would take some hours to do the Math for every single one of those..
User avatar
Blackholyman
Posts: 1292
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Possible to change all sleep timings?

02 Sep 2016, 03:39

Code: Select all

Speed := 0.5

var := "
(
sleep 30
sleep 40
msgbox action
sleep 60
sleep 90
sleep 100
)"

loop, parse, var, `n, `r
    new .= (A_LoopField ~= "^sleep") ? (A_LoopField . "*speed`n") : (A_LoopField . "`n")

msgbox %new%
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
hunter99
Posts: 128
Joined: 20 Jan 2014, 17:57

Re: Possible to change all sleep timings?

02 Sep 2016, 11:07

Hi, try his if you want to change all by the same factor as stated in your 1st post.
This will mult all sleep timings by value in var multiplier.
Use your editor to replace "sleep," with "sleep, multiplier *" NO QUOTES Most let you just keep clicking replace so you can check each is the right one.
You'll get this in script ---> sleep, multiplier * (value determined by a check box)
You can change them all at once, but all by same factor
For test. Be aware that due to the granularity of the OS's time-keeping system Sleep is far from accurate.

Code: Select all

^t:: ;change var based on your check box, here I used .5 for half speed
multiplier := .5 ;put this in script to load a value for var based on check box.
sleep, multiplier * 10000 ;here for test, I mult by .5 to give half time of 5 sec.
msgbox,,, sleep is over
return
hunter99
Edited: Sorry, forgot you were going to use a check box to change value, and I didn't use a var.
Edited2: I'm losing it, reread Blackholyman's 2nd post He answered all.

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 49 guests