Sign in to follow this  
Followers 0
dufran3

Calling a function in an Array

7 posts in this topic

#1 ·  Posted (edited)

Say I have a multi-dimensonal array like so: the 0th , is the display name of the item. The 1st is the Function name, and the 2nd is a general flag used later. How do i call the functions using a loop?

What if one of the functions requires something passed like...the 3rd. The loop I would use to call them is below. I am trying to call the function name that is declared in the array.

Dim $aPwners[3][3] = [ _
                ['Ouch','_iOuch()','0'], _
                ['Death','_iDeath()','0'], _
                ['Pwn','_iPwn()','0'], _
                       ['Rawr','_iRawr($itemtobepassed)','0'] _
            ]oÝ÷ Ù«­¢+Ù½ÈÀÌØí¤ôÀѼÀÌØíAݹÉÍM¥é´ÄìÀÌØíAݹÉÍM¥é±Éɱ¥È($ÀÌØíAݹÉÍlÀÌØí¥ulÅtì±Ðì´ôôôôôôôQ¡¥Ì¥ÌÝ¡É$´ÑÉ她Ѽ±°Ñ¡Õ¹Ñ¥½¸¹µÑ¡Ð¥Ì¥¸Ñ¡ÉÉä°à¸¡}¥=Õ °}¥Ñ ¸¸¹Ñ¸¤!½Ü¼¤¼Ñ¡¥Ìü)9áÐ
Edited by dufran3

Share this post


Link to post
Share on other sites



Ok, I see. What if the function requires a parameter? like funcone? I changed it.

Global $array[3] = ['funcone', 'functwo', 'functhree']

For $i = 0 To UBound($array) - 1
    Call($array[$i])
Next

Func funcone($title)  ;<---- like here
    MsgBox(0, '$title', 'funcone')
EndFunc

Func functwo()
    MsgBox(0, '', 'functwo')
EndFunc

Func functhree()
    MsgBox(0, '', 'functhree')
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Would you not be able to just get $title from within the function? Or set a Global $title = 'whatever' before the function is called, and then just use $title inside the function?

edit - Just had a glance at the Call function in the help file. Your answer for passing args is there. :whistle:

Edited by xcal

Share this post


Link to post
Share on other sites

Would you not be able to just get $title from within the function? Or set a Global $title = 'whatever' before the function is called, and then just use $title inside the function?

edit - Just had a glance at the Call function in the help file. Your answer for passing args is there. :whistle:

Actually calling a function with args is that way better...

I don't like global variables ^^

(After having one of my scripts cleaned from global variables that caused it no longer working ^^)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I just ended up making another element with the "parameter" to pass it.

Dim $aPwners[3][4] = [ _
                ['Ouch','_iOuch()','0','parameter1'], _
                ['Death','_iDeath()','0','parameter2'], _
                ['Pwn','_iPwn()','0','parameter3'], _
                       ['Rawr','_iRawr','0','parameter4'] _
            ]oÝ÷ Ù«­¢+Ø)½ÈÀÌØí¤ôÀѼÀÌØíAݹÉÍM¥é´ÄìÀÌØíAݹÉÍM¥é±Éɱ¥È(
±° ÀÌØíAݹÉÍlÀÌØí¥ulÅt°ÀÌØíAݹÉÍlÀÌØí¥ulÍt¤)9áÐ(
Edited by dufran3

Share this post


Link to post
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
Sign in to follow this  
Followers 0