Indirect reference Mod() error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Indirect reference Mod() error

16 Jun 2015, 18:11

Code: Select all

y:="ur"
ur:=2, ur=mod(++ur,3)     ; Works; ur=0
MsgBox %ur%
ur:=2, %y%=mod(++%y%,3)   ; Error; ur=3?
MsgBox %ur%
ur:=2, %y%:=mod(++%y%,3)  ; Works; ur=0
MsgBox %ur%
The failing code uses valid, allowable syntax.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
hd0202
Posts: 183
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Indirect reference Mod() error

16 Jun 2015, 23:56

You must use ":=mod(..." in all three cases --> expression

Hubert
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Indirect reference Mod() error

17 Jun 2015, 00:03

TAC109 wrote: The failing code uses valid, allowable syntax.
oh really?

TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Indirect reference Mod() error

17 Jun 2015, 01:27

See help, scripts, variables and expressions, expression operators table
,
Comma (multi-statement) [v1.0.46+]. Commas may be used to write multiple sub-expressions on a single line. This is most commonly used to group together multiple assignments or function calls. For example: x:=1, y+=2, ++index, func(). Such statements are executed in order from left to right. Note: A line that begins with a comma (or any other operator) is automatically appended to the line above it. See also: comma performance.

In v1.0.46.01+, when a comma is followed immediately by a variable and an equal sign, that equal sign is automatically treated as an assignment (:=). For example, all of the following are assignments: x:=1, y=2, a=b=c.
Last edited by TAC109 on 17 Jun 2015, 02:05, edited 1 time in total.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Indirect reference Mod() error

17 Jun 2015, 01:51

%y% isn't a variable, it's a reference.
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Indirect reference Mod() error

17 Jun 2015, 23:30

just me wrote:%y% isn't a variable, it's a reference.
Yes, that is probably causing the unexpected result.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput and 106 guests