Trying to get an array to make working buttons. [Script Update]

Ok, so i have this array that makes some GUI buttons and adds the right text to them. my problem is that i don't know how to get the functionality behind them using another array. here is what i have working and the beginning of what i thought would work:

var theButtonNameArray = new Array ("Start", "Resume", "Options");
var theButtonFunctionAction = new Array ("Level1", "Level1", "OptionsScreen");

    function OnGUI () {
    // Make a text field that modifies stringToEdit.        
        for (i = 0; i < theButtonNameArray.length; i++){
                if (GUI.Button (Rect ((Screen.width*.5)-(theButtonPositionWidth*.5), (Screen.height*.5)-(theButtonPositionHeight+theButtonSpace)*(i*3), theButtonWidth, theButtonHeight), theButtonNameArray _+ theButtonFunctionAction*));*_
 _*{*_
 _*Application.LoadLevel(theButtonFunctionAction);*_
 <em>_/*print("Loading Level!");*/_</em>
 _*}*_
 _*}*_
 _*}*_
_*```*_
_*<p>this should be correct right? i'm still getting an error on the Application.LoadLevel or the print line saying: BCE0044: expecting :, found ';'.</p>*_

Try these: GUI Toolbar: http://unity3d.com/support/documentation/ScriptReference/GUI.Toolbar.html GUI Grouping: http://unity3d.com/support/documentation/ScriptReference/GUI.BeginGroup.html GUI Layout has similar things, including a grid: http://unity3d.com/support/documentation/ScriptReference/GUILayout.SelectionGrid.html

And there's probably other ways of doing it too.

Ahh, I've been trying to do something kind-of similar lately....actually not that much but oh well, I see what you're trying to obtain. I'm sure there's a 'clean'er way to do it, by storing 'function call'(is that what Deleguates are for???) or something.

An alternative is to store numerical value, instead of the methods themselves. Then switch() the lastButtonValue and call the desired functions.

OR - not recommended for obscure reasons, yet that could work: store the functions name as Strings in the second array then use eval().

var buttonNames = new Array("myButton1","myButton2","myButton3");
var buttonValues = new Array("myFunc1","myFunc2","myFunc3");

for(i=0;i<buttonNames.length;i++){
    if(/*userPressButton_*/){_
 _eval(buttonValues*+"();");*_
 _*}*_
_*}*_
_*function myFunc1(){//user clicked myButton1;*_
_*}*_
_*function myFunc2(){//user clicked myButton2;*_
_*}*_
_*function myFunc3(){//user clicked myButton3;*_
_*}*_
_*```*_
_*<p>While purely theoretical, I guess this should/could works and create a button for every buttonNames and once clicked. eval() should transform the Strings+() from the array into: </p>*_
_*```*_
<em>_myFunc*();*_</em>
<em>_*```*_</em>