2.0-beta.5 ToolTip optional parameters do not accept null values?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
viv
Posts: 217
Joined: 09 Dec 2020, 17:48

2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by viv » 21 Jun 2022, 03:40

[Moderator's note: Topic moved from Bug Reports.]

Code: Select all

ToolTipAuto("test")
;ToolTip("text", "", "", "") ; x ,y ,which any one of them is null will report an error
Sleep 1000
ExitApp

ToolTipAuto(text, x := "", y := "", wich := 1, cool := 0, time := -1000)
{
    if cool
        CoordMode "ToolTip"
    ToolTip(text, "", "", wich)
    SetTimer(() => ToolTip(, , , wich), time)
}


It works fine in beta4

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by Helgef » 21 Jun 2022, 04:31

Passing "" to mean either 0 or being equivalent to omitting the parameter, was never supported (not in beta at least). The X and Y parameters must be integers or omitted.

Here is one example on how you can handle this,

Code: Select all

ToolTipAuto(text, x := unset, y := unset, wich := 1, cool := 0, time := -1000)
{
    if cool
        CoordMode "ToolTip"
	par := [text,,,wich]
	isset(x) ? par[2] := x : 0
	isset(y) ? par[3] := y : 0
	
    ToolTip(par*)
    SetTimer(() => ToolTip(, , , wich), time)
}
Also, see :arrow: nothing.

Cheers.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by viv » 21 Jun 2022, 06:28

@Helgef

The function was written wrong at the beginning, I wrote x,y as "" in order to test
At first it looked like this

Code: Select all

ToolTip(text, x, y, wich)

Thanks
They work fine this way

But I still don't understand
Why do I pass "" cant work

MsgBox par[2] == ""

This will display 1(true)
This should mean that "" and null are equal, right?

Code: Select all

ToolTipAuto(text, x := unset, y := unset, wich := 1, cool := 0, time := -1000)
{
    if cool
        CoordMode "ToolTip"
	par := [text, , ,wich]
	isset(x) ? par[2] := x : ""
	isset(y) ? par[3] := y : ""
    
    MsgBox par[2] == ""
    MsgBox par[3] == ""
    
    ToolTip(par*)
    SetTimer(() => ToolTip(, , , wich), time)
}

The main thing is that they do work properly before beta5
You can test it in beta4 or beta3

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by Helgef » 21 Jun 2022, 12:48

The main thing is that they do work properly before beta5
No, it works properly now, X and Y must be integers or omitted. "" isn't an integer, nor is it equivalent to omitting the parameter. ToolTip was changed in b5 to return the tooltip's hwnd, and now also has better error reporting, consistent with most other functions.

Please also see :arrow: Variadic function calls,
Notes wrote: Array elements with no value (such as the first element in [,2]) are equivalent to omitting the parameter; that is, the parameter's default value is used if it is optional, otherwise an exception is thrown.
Instead of checking par[2] == "", use :arrow: Array.Has,
has wrote: Returns true if the specified index is valid and there is a value at that position, otherwise false.
my bold
Example,

Code: Select all

msgbox [ ,2].has(1) ; false
This should mean that "" and null are equal, right?
Please see the link to nothing in my previous post.

Cheers.

Edit,
viv wrote:have a nice day
Thanks, you too :wave:
Last edited by Helgef on 22 Jun 2022, 02:30, edited 1 time in total.

viv
Posts: 217
Joined: 09 Dec 2020, 17:48

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by viv » 21 Jun 2022, 20:29

@Helgef

Thank you very much for your explanation
I understand it now

When I used to rewrite functions I never knew how to omit a part by default
I always passed "" in...
Now I understand this method

have a nice day

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

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by guest3456 » 22 Jun 2022, 10:06

viv wrote:
21 Jun 2022, 20:29
When I used to rewrite functions I never knew how to omit a part by default
I always passed "" in...
i believe this is a new feature of v2

as far as i remember, you cannot omit parameters in v1, so you HAD to pass in ""


Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by Helgef » 26 Jun 2022, 12:32

With :arrow: Commit f12398c, you can simply do,

Code: Select all

ToolTipAuto(text, x := unset, y := unset, wich := 1, cool := 0, time := -1000)
{
    if cool
        CoordMode "ToolTip"
    ToolTip text, x?, y?, wich
    SetTimer(() => ToolTip(, , , wich), time)
}
:thumbup:

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by iseahound » 27 Jun 2022, 19:50

@Helgef Do you have a compiled version of beta 6 I can play around with? I'm not too familiar with C++

User avatar
thqby
Posts: 397
Joined: 16 Apr 2021, 11:18
Contact:

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by thqby » 27 Jun 2022, 20:53

iseahound wrote: @Helgef Do you have a compiled version of beta 6 I can play around with? I'm not too familiar with C++
Attachments
AutoHotkey.zip
(603.29 KiB) Downloaded 28 times

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: 2.0-beta.5 ToolTip optional parameters do not accept null values?

Post by lexikos » 27 Jun 2022, 21:49

The current head commit != beta 6. Beta 6 doesn't exist yet.


Post Reply

Return to “Ask for Help (v2)”