"This Func cannot be used as an output variable" Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Gotjek
Posts: 18
Joined: 11 Aug 2022, 11:01

"This Func cannot be used as an output variable"

Post by Gotjek » 11 Aug 2022, 11:19

Hi,

I get this error message when I run my script. Here is the problematic extract :

Code: Select all

hide_word_btn := presenter_gui.Add("Button", , "Cacher le mot")
hide_word_btn.OnEvent("Click", Hide_Word_Btn)  ; <-- The error message points to this line : "Specfically : Hide_Word_Btn"
...
Hide_Word_Btn(*){
    image_name_txt.Text := ""
    image_name_txt.Visible := 0
    Return
}
I searched for the error message on Google and the forum but found very few things.
Could you help me ?
I'm not very good at programming, so I hope to not bother you with an obvious problem I didn't see...

SandyClams
Posts: 63
Joined: 02 Jul 2020, 11:55

Re: "This Func cannot be used as an output variable"  Topic is solved

Post by SandyClams » 11 Aug 2022, 13:25

I have tested and checked nothing, so please forgive me if my insight is not useful, but I'm pretty sure the issue relates to your callback function and your GUI control variable having the same names. Identifiers in AHK are case insensitive, so both of these names are taken internally as being equal. What I assume is that your script interprets hide_word_button as a read-only variable pointing to your callback function. Then when you try to assign to it, the script expects a reference to a variable in the assignment expression, but it gets a reference to your callback instead. I'm not familiar enough with AHK's internals offhand to know where exactly this is happening in the execution of the script, but I bet you can change one of these two names and it will solve your problem.

Gotjek
Posts: 18
Joined: 11 Aug 2022, 11:01

Re: "This Func cannot be used as an output variable"

Post by Gotjek » 12 Aug 2022, 03:45

Exactly ! Thank you very much.

This works :

Code: Select all

hide_word_btn := presenter_gui.Add("Button", , "Cacher le mot")
hide_word_btn.OnEvent("Click", Hide_Word)  ; <-- I removed "_Btn" to have a function woth a different name.
...
Hide_Word(*){
    image_name_txt.Text := ""
    image_name_txt.Visible := 0
    Return
}

Post Reply

Return to “Ask for Help (v2)”