How to a call a function with a number at the end

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 539
Joined: 22 Oct 2015, 17:56

How to a call a function with a number at the end

15 Jun 2019, 20:43

I can't get my head round how to best do something...

Let's say have these functions abc1(), abc2(), abc3()

I want to call one of these functions by random.
So I want to run abcx()
Where x is replaced by a randomly generated number

How can I do this?

Thanks
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to a call a function with a number at the end

15 Jun 2019, 20:51

Code: Select all

abc%therandomlygeneratednumber%()
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: How to a call a function with a number at the end

15 Jun 2019, 20:56

Like this

Code: Select all

#SingleInstance,Force

Numpad1::
	Random,x,1,3
	abc%x%()
return

abc1(){
	msgbox, in abc1
}
abc2(){
	msgbox, in abc2
}
abc3(){
	msgbox, in abc3
}

*ESC::ExitApp
Is it really necessary to have the 3 functions? are you sure that you can't just set up a test in one function? i.e

Code: Select all

abc(x){
	if(x=1){
		do this
	}else if(x=2){
		do this
	}else	{
		something else
	}
}
omar
Posts: 539
Joined: 22 Oct 2015, 17:56

Re: How to a call a function with a number at the end

15 Jun 2019, 21:31

Thanks guys
Perfect
Yes! I need to run code like this 🙂
I'm just playing around with something
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: How to a call a function with a number at the end

15 Jun 2019, 22:06

Hellbent wrote:
15 Jun 2019, 20:56
Is it really necessary to have the 3 functions? are you sure that you can't just set up a test in one function? i.e

Code: Select all

abc(x){
	if(x=1){
		do this
	}else if(x=2){
		do this
	}else	{
		something else
	}
}
For consistency with Hellbent's 1st example, it might be better to show the 2nd example in a way similar to the first one.

Code: Select all

#SingleInstance,Force

^s::
Loop
{
	Random,x,1,3
	abc(x)
}
return

abc(x)
{
	if(x=1)
	{
		msgbox, in abc1
	}
	else if(x=2)
	{
		msgbox, in abc2
	}
	else	
	{
		msgbox, in abc3
	}
}

*ESC::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 248 guests