An #Warn error needs to be identified and handled

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ineuw
Posts: 172
Joined: 11 Sep 2014, 14:12

An #Warn error needs to be identified and handled

13 Sep 2019, 22:06

I have no clue how to deal with this error. I've read the #Warn help page, but I was unsuccessful to implement it to sidestep this.
global variable.jpg
global variable.jpg (99.65 KiB) Viewed 491 times
Win 10 Professional 64bit 21H2 16Gb Ram AHK current as of 2021-12-26 .
gregster
Posts: 9067
Joined: 30 Sep 2013, 06:48

Re: An #Warn error needs to be identified and handled

14 Sep 2019, 00:17

First of all, #warn-ings are not errors. Warnings are about potential causes for errors... on first glance I didn't even know why it would warn you about the variable in_len, since this variable seems to get assigned in your script before it gets read.

But then there is the line #if out_len := (in_len +4) which probably doesn't do what you expect anyway. Please remove it - in its current form, it doesn't make sense.

Perhaps you meant instead

Code: Select all

if (out_len = (in_len +4) )
As you probably know, the #if directive is only used for creating (or disabling) context-sensitive hotkeys and hotstrings... you seem to try to use it as a regular if-check... but even then you shouldn't use the := assignment operator, but the = operator. At the moment, this expression (almost) always evaluates to true, as it just assigns a non-zero value to a variable.

But the actual problem is most likely this special behaviour of the #if-directive:
https://www.autohotkey.com/docs/commands/_If.htm#General_Remarks wrote:The expression may also be evaluated whenever the program needs to know whether the hotkey is active.
That means, the #if out_len := (in_len +4) line may be executed even before in_len is first assigned in the Alt+F12 hotkey (which happens in line: in_len := strlen(in_put) ). In this case, the warning would be issued...

Luckily, the (corrected) line if (out_len = (in_len +4) ) - without a directive - wouldn't be affected by this problem, as it would be executed only after in_len has been assigned.
User avatar
ineuw
Posts: 172
Joined: 11 Sep 2014, 14:12

Re: An #Warn error needs to be identified and handled

14 Sep 2019, 01:11

gregster, much thanks again, it makes perfect sense after your explanation.
Win 10 Professional 64bit 21H2 16Gb Ram AHK current as of 2021-12-26 .

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, GEOVAN and 152 guests