assignment in V2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

assignment in V2

01 Nov 2013, 09:10

Since V2 removed "=" assignment, I cannot use the following code.
var =
(
line1
line2
line3
}

but the replacement which I know is too complex. such as:
var := "line1`n"
. "line2`n"
. "line3`n"

Who can tell me a simple one?

Thanks.
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: assignment in V2

01 Nov 2013, 09:30

This works in 1.1

Code: Select all

var :=
(
"This is a string.
that is a very long string
and it spans multiple
lines. "
)
MsgBox, % var
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: assignment in V2

01 Nov 2013, 09:45

trismarck wrote:This works in 1.1

Code: Select all

var :=
(
"This is a string.
that is a very long string
and it spans multiple
lines. "
)
MsgBox, % var
Thanks, but V2 does not support this format.
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: assignment in V2

01 Nov 2013, 10:37

Code: Select all

Assign, var,
(
line1
line2
line3
)


Assign(p) {
	return p
}
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: assignment in V2

01 Nov 2013, 18:21

isurface wrote:Thanks, but V2 does not support this format.
It just needs the Q option, so that the second quote mark is interpreted as a close-quote.

Code: Select all

var :=
(Q
"This is a string.
that is a very long string
and it spans multiple
lines. "
)
MsgBox, % var
Of course, the previous two posts show better alternatives.
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: assignment in V2

02 Nov 2013, 01:20

Thanks all, they are just what I wanted.

Hi Jethrow,

Could you explain this a bit more? What's "comma" means here? I have never seen this syntax.
jethrow wrote:

Code: Select all

Assign, var,
(
line1
line2
line3
)


Assign(p) {
	return p
}
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: assignment in V2

02 Nov 2013, 01:27

User-defined function(s) in v2 can be called in command syntax. jethrow defined an assign function and called it in command syntax. Since the function is returning a value, calling it in command syntax requires an OutputVar, in this case var. Comma is needed as it requires 2 parameters: OutputVar and Value(value to assign). You can omit the first comma after assign as AHK has smart comma handling
Last edited by Coco on 02 Nov 2013, 01:32, edited 1 time in total.
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: assignment in V2

02 Nov 2013, 01:31

isurface wrote:Could you explain this a bit more? What's "comma" means here? I have never seen this syntax.
It's one of the new amazing features of AHK v2 - any function can be called as a command, and any command can be called as a function. Really, they are just executable statements. So, the following are 2 statements are equivalent:

Code: Select all

var := Assign("value")
Assign, var, value

Assign(p) {
    return p
}
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: assignment in V2

02 Nov 2013, 02:46

Amazing, very concise. It looks like ASM.

Code: Select all

add, var, 2, 3
add(p, q) {
    return p + q
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: ntepa and 59 guests