Trying to migrate from v1.1 to v2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
StefOnSteroids
Posts: 77
Joined: 08 Aug 2015, 10:22

Trying to migrate from v1.1 to v2

05 Mar 2023, 04:45

I expected the transition to be easier.
Had put high hopes into the script converter, but I still cannot get this to work:

v1:

Code: Select all

MsgBox, 64, Ahk Version: %A_AhkVersion%, 
(LTrim
  ScriptPath:`t%A_ScriptFullPath%
  WorkingDir:`t%A_WorkingDir%
  ScriptDir:`t`t%A_ScriptDir%
  SendMode:`t%A_SendMode%
  TitleMatchMode:`t%A_TitleMatchMode%
)
Return
v2 (generated by the script converter)

Code: Select all

MsgBox("
(LTrim
  ScriptPath:`t" A_ScriptFullPath "
  WorkingDir:`t" A_WorkingDir "
  ScriptDir:`t`t" A_ScriptDir "
  SendMode:`t" A_SendMode "
  TitleMatchMode:`t" A_TitleMatchMode "
)", "Ahk Version: " A_AhkVersion, 64)
Return
What's wrong with the code above?
Read up on the various sections in the manual, but it's too technical, it sends me jumping from one link to the next.

Example 2:
It's from a popup menu that works fine for me in v1, but throws an error in v2.

v1:

Code: Select all

Menu, MyFoc, Add, CopyAll, #a
Menu, MyFoc, Add, New All-in, All-in
v2 (generated by the script converter)

Code: Select all

MyFoc.Add("CopyAll", #a)
MyFoc.Add("New All-in", All-in)
The first line is supposed to trigger a hotkey
The second should jump to a label.
User avatar
boiler
Posts: 17297
Joined: 21 Dec 2014, 02:44

Re: Trying to migrate from v1.1 to v2

05 Mar 2023, 06:49

For the first part:

Code: Select all

MsgBox(
(
  "ScriptPath:`t" A_ScriptFullPath "`n"
  "WorkingDir:`t" A_WorkingDir "`n"
  "ScriptDir:`t`t" A_ScriptDir "`n"
  "SendMode:`t" A_SendMode "`n"
  "TitleMatchMode:`t" A_TitleMatchMode
), "Ahk Version: " A_AhkVersion, 64)
Return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Trying to migrate from v1.1 to v2

05 Mar 2023, 07:19

Code: Select all

#Requires AutoHotkey v2.0.2

MsgBox(
	(Join`s'`n'`s
		'ScriptPath:`t' A_ScriptFullPath
		'WorkingDir:`t' A_WorkingDir
		'ScriptDir:`t`t' A_ScriptDir
		'SendMode:`t' A_SendMode
		'TitleMatchMode:`t' A_TitleMatchMode
	),                            ; Text
	'Ahk Version: ' A_AhkVersion, ; Title
	64                            ; Options
)

Code: Select all

MyFoc.Add("CopyAll", copyAllHandler(ItemName, ItemPos, MyMenu) => myWinAfunc('asdbhjshdg'))
MyFoc.Add("New All-in", allInHandler(ItemName, ItemPos, MyMenu) => All_in())

#a::
myWinAfunc(thisHotkey) {

}

All_in() { ; All-in with a dash is not a valid identifier name. also Labels are mostly not used in v2 as very few things can actually interact with them(specifically goto, continue and break)

}
its no use trying to transpile v1 1:1 to v2 because the code that that produces makes little to no sense. instead, rewrite the code in v2 from the ground up, using v2 idioms
StefOnSteroids
Posts: 77
Joined: 08 Aug 2015, 10:22

Re: Trying to migrate from v1.1 to v2

05 Mar 2023, 14:54

Thank you both. I really appreciate it.

@boiler
I would have never guessed I need manual linefeeds. The help file claims I don't have to, because "... a linefeed (`n) is present between lines", thanks to smart behavior, similar to v1.
And the script converter did not insert them, either.

@swagfag
I learned a lot from your examples, especially the menu definition (after reading up about in the help file again and again). Still not sure, whether I really grasp what's going on here. But you got my old script working again. :clap:
Thanks also for the hint about labels, and dashes not being valid in identifiers.
swagfag wrote:
05 Mar 2023, 07:19
its no use trying to transpile v1 1:1 to v2 because the code that that produces makes little to no sense. instead, rewrite the code in v2 from the ground up, using v2 idioms
I am beginning to see your point.
The learning curve is steep, though. For an occasional user like me, the new syntax is intimidating, to say the least. Very convoluted, with complex nesting and quoting. Despite your examples I triggered errors en masse.

There is no way I can create/adjust my menus on the fly, like I used to do in v1. And I have tons of custom menus, for all programs I use. Converting them, or rather rewriting them, will take a lot of time.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 44 guests