Jump to content

Array of Functions


Recommended Posts

Is it possible to make an array that sends to the proper function? Right now I have them all in if statements.

Something like this...

$Array[2] = "Option_4"; will have 10 - 20 options

$Func = "_" & $Array[2] & "()"

$Func ; This should = _Option_4()

Func _Option_1()
  Does something
EndFunc

Func _Option_2()
  Does something
EndFunc

Func _Option_3()
  Does something
EndFunc

Func _Option_4()   <------ goes here
  Does something
EndFunc

Func _Option_5()
  Does something
EndFunc

Func _Option_6()
  Does something
EndFunc
Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

Is it possible to make an array that sends to the proper function? Right now I have them all in if statements.

Something like this...

$Array[2] = "Option_4"; will have 10 - 20 options

$Func = "_" & $Array[2]

$Func() ; This should = _Option_4()

Func _Option_1()
  Does something
EndFunc

Func _Option_2()
  Does something
EndFunc

Func _Option_3()
  Does something
EndFunc

Func _Option_4()   <------ goes here
  Does something
EndFunc

Func _Option_5()
  Does something
EndFunc

Func _Option_6()
  Does something
EndFunc
I'm actually trying to find out how to do the same thing but with arrays.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

I figured it out!! Woohooo

Let me put a brief description up so you'll understand how I came to make this work.

1) I read a line of text in using the splitstring function ; which is used in an array ($Array[])

2) the second variable ($Array[1]) is what I check for ( there are 14 different possible values )

3) it returns 'Option 1'

4) I create a variable like so ... $Func = "_" & $Array[2] ------> which equals "_Option 1" ; without the qoutes

5) Then I just activate it with the 'Call' fuction -------> Like so ... "Call ($Func)" ; again without the quotes

NOTE: You must have a Func with the value in $Func for it to work.

BAM!!! works perfectly for me.

Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

I figured it out!! Woohooo

Let me put a brief description up so you'll understand how I came to make this work.

1) I read a line of text in using the splitstring function ; which is used in an array ($Array[])

2) the second variable ($Array[1]) is what I check for ( there are 14 different possible values )

3) it returns 'Option 1'

4) I create a variable like so ... $Func = "_" & $Array[2] ------> which equals "_Option 1" ; without the qoutes

5) Then I just activate it with the 'Call' fuction -------> Like so ... "Call ($Func)" ; again without the quotes

NOTE: You must have a Func with the value in $Func for it to work.

BAM!!! works perfectly for me.

Ok I got it.

Thanks.

Edited by blademonkey

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...