Create dynamic function Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
HugoM
Posts: 37
Joined: 06 Mar 2018, 14:21

Create dynamic function  Topic is solved

Post by HugoM » 28 Nov 2022, 06:24

Moin, ;)

I have something like

FuncKind := "A"
if (FuncKind == "A")
MyFunc := FuncA
if (FuncKind == "B")
MyFunc := FuncB
MyFunc

This works fine.
Is it possible to write something like

MyFunc := "Func" . FuncKind

I tried to understand the docs "Func Object" and "Function Objects" but cannot figure out how to manage my task.
Is it possible and if so how?
Thx in advance. HugoM

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

Re: Create dynamic function

Post by thqby » 28 Nov 2022, 07:09

MyFunc := Func%FuncKind%

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

Re: Create dynamic function

Post by lexikos » 28 Nov 2022, 18:43

There is nothing about this that is specific to functions. This is not creating a function, dynamic or otherwise. You are just picking between multiple variables based on the name of the variable. thqby's suggestion will work regardless of whether FuncA and FuncB refer to functions or to other types of values (but for the latter, there is less reason to use individual dynamic variables; an array or map should probably be used instead).

HugoM
Posts: 37
Joined: 06 Mar 2018, 14:21

Re: Create dynamic function

Post by HugoM » 29 Nov 2022, 06:36

So easy!
Thank You and all the best

Post Reply

Return to “Ask for Help (v2)”