
Arrays and Functions
I have an array which contains the names of functions (a1() and a2()) and
a function is randomly picked. My problem is that the function name is stored
in a variable (choosescript) and I cannot work out how to run the function.
Here is the script:
function mine() {
var scriptlist = new Array;
var choosescript;
scriptlist[0] = "a1"
scriptlist[1] = "a2"
choosescript = scriptlist[Math.floor(Math.random() * scriptlist.length)];
Any ideas please?
Matt (Matt0220@AOL.com)

Re: Arrays and Functions
if (choosescript.equals("a1")) a1();
if (choosescript.equals("a2")) a2();
There are other ways to do this, but they would require more changes.
PC2
Matt <matt0220@aol.com> wrote in message news:39ccdeac$1@news.devx.com...
>
> I have an array which contains the names of functions (a1() and a2()) and
> a function is randomly picked. My problem is that the function name is
stored
> in a variable (choosescript) and I cannot work out how to run the
function.
> Here is the script:
>
> function mine() {
> var scriptlist = new Array;
> var choosescript;
> scriptlist[0] = "a1"
> scriptlist[1] = "a2"
> choosescript = scriptlist[Math.floor(Math.random() * scriptlist.length)];
>
> Any ideas please?
>
> Matt (Matt0220@AOL.com)