How do you use a variable in a line of code?

Hello,
Alright, I am having a big problem here and I cannot for the life of me find a solution to it.

I have a Javascript file that contains my classes, as of now there is only one.

//This script holds all classes and there data

class trackInfo
{
	var scenename : String;
	var name : String;
	var length : int;
	var bestlaptime : float;
	var type : String;
	var series : String;
}

I then have another script that holds the instances and there variable values.

//Track Info Holder

static var track1 = trackInfo();
	track1.scenename = "track1";
	track1.name = "Townsville Practice Day";
	track1.length = 300;
	track1.bestlaptime = 999;
	track1.type = "Hybrid Supercross";
	track1.series = "Queensland ClubCross";
	
static var track2 = trackInfo();
	track2.scenename = "track2";
	track2.name = "Supercross";
	track2.length = 300;
	track2.bestlaptime = 999;
	track2.type = "Hybrid Supercross";
	track2.series = "Queensland ClubCross";

The issue arises when I try to set one of these value dependent on what scene I am in. So the normal way would be the following

//On GUI

bestlaptime = TrackInfoHolder.track1.bestlaptime;

But rather than have track1 in there, I want it to be dependent on my scene, my scene names are track1, track2, track3 respectively.

So my thought would be something like this

bestlaptime = TrackInfoHolder.(Application.loadedLevelName).bestlaptime;

Of course I have tried this and it doesn’t work. Is there any other way to go about a solution to this.

Thank You for your time!
Ramon Brand

You need to use something else rather than pure static variables. You should consider using a Dictionary where the key is the loaded level name:

   static var tracks = new Dictionary.<string, trackInfo>();

   TrackInfoHolder.tracks[Application.loadedLevelName].bestLapTime = xxxx;

This Unity Gems article has a section showing information on using Lists and Dictionaries in Unity Script.