Why does my script not work?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fraudeerbeer
Posts: 4
Joined: 22 Jan 2023, 15:45

Why does my script not work?

Post by fraudeerbeer » 27 Jan 2023, 19:24

Hi everyone,

I made a script to generate a random number from 1 to 4 and if the number were to be 1 the cursor would click in location A, if the number were to be 2 the cursor would click in location B etc.

I made this script in V1 and it worked perfectly fine
(1.ahk)
1.ahk
(374 Bytes) Downloaded 40 times
but then I tried to translate it to V2 and I kept on getting an error "call to nonexistend function" (2.ahk)
2.ahk
(360 Bytes) Downloaded 37 times
image.png
Screenshot of error msg
image.png (11.92 KiB) Viewed 839 times
I annot figure out what I did wrong, could someone please assist me?

Thanks in advance,

FraudeerBeer

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

Re: Why does my script not work?

Post by boiler » 27 Jan 2023, 19:52

Your main problem is that you are not running the script using v2. That error is an v1 error, and you would have gotten an error on an earlier line because your hotkey function is not enclosed in braces { } as is required in v2.

It would be better if you posted your code in the body of the post in between [code][/code] tags so members can immediately view your code without having to download it.

fraudeerbeer
Posts: 4
Joined: 22 Jan 2023, 15:45

Re: Why does my script not work?

Post by fraudeerbeer » 28 Jan 2023, 08:45

Hi @boiler,

I am not very experienced with V2 yet. Could you explain more carefully where I have to put the brackets {}?

Thanks,

-FraudeerBeer.

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

Re: Why does my script not work?

Post by boiler » 28 Jan 2023, 09:26

It’s about the first thing shown on the documentation page for hotkeys. Looking at the documentation should always be your first step.

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

Re: Why does my script not work?

Post by mikeyww » 28 Jan 2023, 09:54

Also: there are situations where using #Requires helps.

Code: Select all

#Requires AutoHotkey v2.0

^k:: {
 Loop 10
  Switch Random(1, 4) {
   Case 1: Send 1
   Case 2: Send 2
   Case 3: Send 3
   Case 4: Send 4
  }
}
Explained: Launcher

Or:

Code: Select all

#Requires AutoHotkey v2.0
coord := [[500, 250], [1200, 300], [1700, 950], [180, 900]]

^k:: {
 Loop 2 {
  c := coord[Random(1, 4)]
  Click c[1], c[2]
 }
}

Post Reply

Return to “Ask for Help (v1)”