Page 1 of 1

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

Posted: 15 Jun 2019, 20:43
by omar
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

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

Posted: 15 Jun 2019, 20:51
by swagfag

Code: Select all

abc%therandomlygeneratednumber%()

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

Posted: 15 Jun 2019, 20:56
by Hellbent
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
	}
}

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

Posted: 15 Jun 2019, 21:31
by omar
Thanks guys
Perfect
Yes! I need to run code like this 🙂
I'm just playing around with something

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

Posted: 15 Jun 2019, 22:06
by SOTE
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