Is AHK v2 better than v1?

Talk about anything
Patrycy
Posts: 15
Joined: 24 May 2024, 05:48

Is AHK v2 better than v1?

Post by Patrycy » 24 May 2024, 06:54

I barely used this application, so I'm curious as to which one I should be using to make some scripts for older games, which version be better for this?

User avatar
boiler
Posts: 17424
Joined: 21 Dec 2014, 02:44

Re: Is AHK v2 better than v1?

Post by boiler » 24 May 2024, 07:45

Yes, v2 is much better than v1. Not only is it the version that will continue to be maintained, it eliminates most of the confusion that made v1 so frustrating for beginners to learn. In general, its syntax and structure are more modern, which results in a much better coding experience.

User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: Is AHK v2 better than v1?

Post by andymbody » 24 May 2024, 16:33

V2 is more consistent and more reliable and will tell you when you have make a syntax mistake. When mistakes are made in V1, it will simply "not work", or produce incorrect result with no explanation why. It will take much longer to track down the cause of errors, even when they are staring you in the face.

I do not recommend v1, especially for AHK rookies. Heck, I've been using it for about 8 years and am still a rookie.

User avatar
CoffeeChaton
Posts: 46
Joined: 11 May 2024, 10:50

Re: Is AHK v2 better than v1?

Post by CoffeeChaton » 24 May 2024, 21:32

Code: Select all

#Requires AutoHotkey v1.1.33+
; #Warn All, MsgBox

MsgBox, % foo(99) ; just 99 -> "caseEnd" , but not has "ELSE"
MsgBox, % foo(0) ; just "caseEnd", not "ELSE"
MsgBox, % foo(1) ; just "caseEnd", not "ELSE"
MsgBox, % foo(2) ; just "caseEnd", not "ELSE"
MsgBox, % foo(3) ; just "caseEnd", not "ELSE"
MsgBox, % foo(4) ; just "caseEnd", not "ELSE"

;@ahk-neko-format-ignore-start
foo(var1) {
    if (var1 = 99), Return "Case99"
        MsgBox, % "99"
    
    if (var1 = 0) , Return "caseA"
    if (var1 = 1) , Return "caseB"
    if (var1 = 2) , Return "caseC"
    if (var1 = 3) , Return "caseD"

    MsgBox, % "ELSE"
    Return "caseEnd"
}
;@ahk-neko-format-ignore-end
case of "not work" or produce incorrect result with no explanation why.

When forget to open #warn
if (), XXX or if () XXX, the XXX in if line
v1 will always exceed my imagination. :cry:

If you are a beginner, i am recommended to start with v2.

guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: Is AHK v2 better than v1?

Post by guest3456 » 03 Jun 2024, 00:22

CoffeeChaton wrote:
24 May 2024, 21:32
if (), XXX or if () XXX, the XXX in if line
v1 will always exceed my imagination. :cry:
nowhere on this page does it say that you can add a comma and then a statement on the same line

only when using the IfCommand commands can you sometimes do it:
https://www.autohotkey.com/docs/v1/lib/IfEqual.htm

my guess is that the comma is ignored and your code actually works like this:

Code: Select all

foo(var1) {
    if (var1 = 99), Return "Case99"
        MsgBox, % "99"
    
    if (var1 = 0) , Return "caseA"
        if (var1 = 1) , Return "caseB"
            if (var1 = 2) , Return "caseC"
                if (var1 = 3) , Return "caseD"
                    MsgBox, % "ELSE"
                    
    Return "caseEnd"
}


User avatar
CoffeeChaton
Posts: 46
Joined: 11 May 2024, 10:50

Re: Is AHK v2 better than v1?

Post by CoffeeChaton » 03 Jun 2024, 00:47

@guest3456

I know these rules, but when I switch from other languages, I often step on rake :crazy: and forget to enable #warn, there is no prompt, so I have to manually write some static diagnostics in the vscode extension.

I just want to express the syntax of v2, which is more modern, and at the same time have clearer hints for some common mistakes.

tks boiler remind me
image.png
image.png (124.54 KiB) Viewed 368 times
image.png
image.png (113.89 KiB) Viewed 368 times
Last edited by CoffeeChaton on 03 Jun 2024, 11:54, edited 1 time in total.

User avatar
boiler
Posts: 17424
Joined: 21 Dec 2014, 02:44

Re: Is AHK v2 better than v1?

Post by boiler » 03 Jun 2024, 02:32

@CoffeeChaton — Do not put img tags around attached images. That results in broken image icons. They are used when you have a URL to an image file.

Post Reply

Return to “Off-topic Discussion”