Page 1 of 1

Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 20:06
by iseahound
I remember doing Sleep % 30 + 5000. When did this change?

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 20:10
by Hellbent
lol
you can do the same with mousemove and others

That right there is why people moan about inconsistencies in ahk lol

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 20:18
by mikeyww
The trend is useful, as it seems that most of the parameters that are expected to be numeric can be an expression as well.

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 20:31
by swagfag
1.0.25 - January 12, 2005 wrote:Added support for expressions in commands that have numeric parameters, such as StringLeft. In addition, IF-statements may use complex expressions by including a parenthesis as the first character, e.g. if (X < Y + 10) and (Color = "Blue"). Finally, Var:=expression has been added to assign the result of an expression to a variable, e.g. Var := 100*X + 1/3. See Expressions for details about operators, string concatenation, and easier access to arrays. [thanks Joost Mulders]
well over 16 years ago, apparently

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 21:28
by iseahound
I don't believe it. All the code on this forum uses Sleep % expr. I was only porting from v2 to v1 that I realized it works.

https://autohotkey.com/board/topic/39023-sleep-var/
tidbit wrote: j:= ;your equation/expression here, can include variables as well.
sleep, %j%
or
sleep, % ;your equation/expression here, can include variables as well. include 1 space after the %
like that?
https://autohotkey.com/board/topic/68028-sleep-variable/
https://autohotkey.com/board/topic/111988-using-a-global-variable-to-modify-sleep-length/
https://autohotkey.com/board/topic/99171-sleep-variable-not-working/
viewtopic.php?t=66300

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 21:45
by swagfag
well i must come clean and say i wasnt very diligent in checking this, i just went off of what was documented. it may have been possible to do this even earlier than that. luckily for u, most all interpreters are available, so u can try it out on ur own

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 22:46
by lexikos
:lol:

Numeric Parameters

Numeric parameters accept a literal number or an expression, and can be identified by phrasing like "This parameter can be an expression."

For historical reasons, simple variable references alone or combined with digits are not interpreted as expressions. For example:

Code: Select all

Sleep %n%000  ; Sleep for n seconds.
Sleep %m%     ; Sleep for m milliseconds.
To perform a double-deref in such cases, enclose the expression in parentheses: Sleep (%m%)
...
Numeric parameters allow and ignore the percent prefix.

Source: Scripting Language | AutoHotkey

Re: Since when was sleep an expression in v1???

Posted: 25 Sep 2021, 23:08
by guest3456
iseahound wrote:
25 Sep 2021, 21:28
I don't believe it. All the code on this forum uses Sleep % expr. I was only porting from v2 to v1 that I realized it works.
there are many examples of commands in v1 that the docs say "can be an expression" for certain params. not just sleep. our converter specifically handles those parameters differently:

https://github.com/mmikeww/AHK-v2-script-converter/blob/a6aa84fa40a764246f3639b422ba6c2f8223fa01/ConvertFuncs.ahk#L58

Re: Since when was sleep an expression in v1???

Posted: 26 Sep 2021, 15:59
by Capn Odin
Yeah it has been like this for a while but the reason you see people use % is because it always work so there is no reason to try and remember which commands accepts expressions. I always use % myself unless I only need something that can be written using command syntax.