AHK 2.0 and Braces Problem

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Buddha Nature
Posts: 34
Joined: 13 Feb 2022, 06:42

AHK 2.0 and Braces Problem

Post by Buddha Nature » 24 Dec 2022, 07:56

I am tinkering around with AutoHotkey v2.0. For part of my tinkering I have the following block of code (which is just a snippet of a much longer complete code):

Code: Select all

While WinActive(winTitle) {

 ;Input, key, VL1, % ""
 key := InputHook(VL1, "")

 Switch
 { Case !WinActive(winTitle)
      , StrLen(ErrorLevel) > 3: state =
   Case Instr(".!?%"  , key)   : state = 1
   Case Instr("`t `n", key)   : state += (state = 1)
   ;Default                    : Send % state = 2 ? Format("`b{:U}", key) : ""
   Default                    : Send state = 2 ? Format("`b{:U}", key) : ""
                                state =
 }
}
When I try to run the code the interpreter throws out the following error message:
Error: Unexpected "}"
Text: state = }
Line: 13
File: E:\PORTABLES\- AutoHotKey\AutoHotkey v2.0.0\Scripts\Test.ahk2

The program will exit.
Problem with this is that Line 13 of the code is the line that ends state = There is no closing brace } on that line at all, yet the interpreter seems to think that what is on that line is state =}

What is going wrong with this? It seems the interpreter isn't matching up braces properly and thinking there is braces where none exist.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: AHK 2.0 and Braces Problem

Post by mikeyww » 24 Dec 2022, 07:59

This [post was formerly in] the v1 forum.

I did not try the script, but noted the first line of AutoHotkey's change log.
Removed literal assignments: var = value
https://www.autohotkey.com/docs/v2/v2-changes.htm#legacy-syntax-removed

Reading that page may accelerate the success of tinkering!
Last edited by mikeyww on 24 Dec 2022, 08:38, edited 1 time in total.

User avatar
Buddha Nature
Posts: 34
Joined: 13 Feb 2022, 06:42

Re: AHK 2.0 and Braces Problem

Post by Buddha Nature » 24 Dec 2022, 08:24

Sorry for posting in the wrong forum.

Have spent the last 20 minutes trying to read the document you point to and quickly ended up utterly baffled. I think I'll just stick with my AHK 1.1 script, it works and I'm happy with it anyway. I don't have the makings of a coder in me. Ah, well... Another life perhaps. Thanks for pointing me in an appropriate direction Mike.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: AHK 2.0 and Braces Problem

Post by mikeyww » 24 Dec 2022, 08:35

Code: Select all

state := 1
state := ""
Etc.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: AHK 2.0 and Braces Problem

Post by BoBo » 24 Dec 2022, 08:36

Moved to AHK 2.0 forum section. HTH

User avatar
Buddha Nature
Posts: 34
Joined: 13 Feb 2022, 06:42

Re: AHK 2.0 and Braces Problem

Post by Buddha Nature » 24 Dec 2022, 10:24

Thanks very much Mike. I did as you indicated and that fixed that issue. But then the interpreter started finding serial other errors in the script I was trying to translate into v2.0: at that I definitely threw in the towel. I'll forget a about v2.0 and just stumble my way around v1.1 which works fine for me anyway.

Post Reply

Return to “Ask for Help (v2)”