Page 1 of 1

[Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 15:01
by HakitoJin
I just want my invalid expressions to return null like they used to, is that too much to ask?

Object warnings were annoying too until I found how to disable them in the documentation, so I'm hoping there's something for mismatch too.
Here's the code for that unrelated object warning thing, just call it once:

Code: Select all

NoObjectWarn() ;From Autohotkey's V2 Documentation, find it by going to "Object" and then "Debugging"
{
	Static Enabled
	iF not Enabled
		"".base.__Get:="".base.__Set:="".base.__Call:=Func("NoObjectWarn") , Enabled:=1
    return
}
Type mismatch must die.

Re: [Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 15:27
by Flipeador
NO. This helps a lot when it comes to detecting errors, it is one of the best things that have been implemented. v1 is disgusting, v2 is a little more serious.
Anyway, you can always stay using v1.

Re: [Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 15:48
by HakitoJin
Type mismatch IS the error though.

Re: [Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 17:05
by lexikos
"Type mismatch" is an error message, not the error. The error is what you've done to cause the error message: attempted to perform math on an invalid value. You don't want to prevent the error; you want to change how the script reacts to the error.

The only way to do that is to modify the program itself, in C++.

Re: [Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 17:32
by HakitoJin
lexikos wrote:"Type mismatch" is an error message, not the error.
Yes I know, I am just saying it's as bad as an error message, and now I can't do iF(x+y="") to check if one of two numbers is empty, nor iF(x&1) to check for even numbers.
lexikos wrote:The only way to do that is to modify the program itself, in C++.
So... why wasn't the old way of dealing with errors kept as an option?
Surely performance is not the issue, because there's no way manually initializing variables using AHK is faster than having it done automatically in C++.

Re: [Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 17:54
by Flipeador
You can not do it that way because it is not what corresponds. V1 is full of bad programming practices, this is a clear example. You are trying to make something work in a very dirty way.
To check if it is a number use is or the Type function.
I think you should stay with v1.

Re: [Ahk2] How to disable "Type mismatch"?

Posted: 25 Aug 2018, 17:55
by guest3456
HakitoJin wrote: and now I can't do iF(x+y="") to check if one of two numbers is empty, nor iF(x&1) to check for even numbers.
exactly. THESE are your errors. its not the error message's fault.

see Flipeador above for "is a number"

and to check for even numbers you should use Mod()
https://autohotkey.com/docs/commands/Math.htm#Mod