Random selection of variable name from array

I want to use Random.Range to select an element of an array arr(“list1”,“list2”) so that I can load objects in the order specified in arr(“listX”). Here is my code, it works so that I am randomly selection one of the strings from arr but how do I then access the variable with the name specified in that string.

var presentationLists = new Array("list1","list2");
var list1= new Array("Obj1","Obj2");
var list2= new Array("Obj2","Obj1");
var pres_list = new Array();

var viewTime:int=3;
var Obj1:GameObject;
var Obj2:GameObject;
var tmpObject:GameObject;


function Start () {
    var r = Random.Range(0,presentationLists.length-1);
    var listNum=presentationLists[r];
    pres_list = //this is what I'm trying to get. How do I get the array based on the string  in listNum?


    for(var n = 0; n < pres_list.length; n++){
    	var tmpString:String = pres_list[n];
    	tmpObject=GameObject.Find(tmpString);
    	tmpObject.transform.position = Vector3(1013,499,1285);
    	yield WaitForSeconds(viewTime);
    	tmpObject.transform.position = Vector3(0,0,0);
    }
}

I think you have two choices.

Create an array of array and like that you don’t need any more the listNum:

var list1= new Array("Obj1","Obj2");
var list2= new Array("Obj2","Obj1");
 
var lists: Array = [list1, list2];

Or (for me is better) create a new Object with your list(in public) inside and after create an array of that Object.

I hope this help…

You can’t, and is not even needed.

If you have a 2 arrays of GameObjects names, presentationLists should be an array with this 2 arrays.

I’m not familiar with UnityScript but it could look like this:

var lists = new Array(new Array("Obj1","Obj2"),new Array("Obj2","Obj1"));
var pres_list = new Array();

var viewTime:int=3;
var tmpObject:GameObject;

function Start () {
    var r = Random.Range(0,lists.length-1);
    pres_list=lists[r];

    for(var n = 0; n < pres_list.length; n++){
        var tmpString:String = pres_list[n];
        tmpObject=GameObject.Find(tmpString);
        tmpObject.transform.position = Vector3(1013,499,1285);
        yield WaitForSeconds(viewTime);
        tmpObject.transform.position = Vector3(0,0,0);
    }
}