HighScore Names

This is currently my script for a local high score system in my game. Everything works, but the inputting the names. What I want is for once you get to the screen with the high scores, you will be prompted to enter your initials (if you do get a high score). It then stores the initials with the correct score (which are two separate arrays). I’m just not sure how to get the string from the textfield that you enter to be paired with the score.

var position : int;		// position to enter new hgih score
var positionName : int;		// position where to enter name
var switched : boolean = false;		// whether or not a score has been replaced

var HighS1 : GUIText;
var HighS2 : GUIText;
var HighS3 : GUIText;

var Name1 : GUIText;
var Name2 : GUIText;
var Name3 : GUIText;

var entName : String = "";

function OnGUI () {
entName = GUI.TextField (Rect (Screen.width/2 - 25, Screen.height/2 + 125, 50, 20), entName, 3);
}

function Start(){	
	HighScore();
}

function HighScore(){
	for(position = 0; position < GlobalStats.High.length; position++){
		if(switched == false && (GlobalStats.TotalScore > GlobalStats.High[position])){		// replace with new score
			positionName = position;
			switched = true;
			for(curPos = GlobalStats.High.length - 1; curPos > 0;curPos--){    // shift scores to the right
				GlobalStats.High[curPos] = GlobalStats.High[curPos - 1];
			}
			GlobalStats.High[position] = GlobalStats.TotalScore;
		}
	}
	
	GlobalStats.HighName[positionName] = entName;
	
	HighS1.text = GlobalStats.High[0].ToString();
	HighS2.text = GlobalStats.High[1].ToString();
	HighS3.text = GlobalStats.High[2].ToString();
	
	Name1.text = GlobalStats.HighName[0].ToString();
	Name2.text = GlobalStats.HighName[1].ToString();
	Name3.text = GlobalStats.HighName[2].ToString();
}

Maybe you could just use positionName and change the value each OnGUI? If your backing end storage is PlayerPrefs, then you probably should use another variable that guards writing to PlayerPrefs only when the user is done editing the name…

Oh and you probably need to reorganize the name array when you reorganize the score array…

var position : int;     // position to enter new hgih score
var positionName : int;     // position where to enter name
var switched : boolean = false;     // whether or not a score has been replaced

var HighS1 : GUIText;
var HighS2 : GUIText;
var HighS3 : GUIText;

var Name1 : GUIText;
var Name2 : GUIText;
var Name3 : GUIText;

var entName : String = "";

function OnGUI () {
  entName = GUI.TextField (Rect (Screen.width/2 - 25, Screen.height/2 + 125, 50, 20), entName, 3);

  // ******************************************
  // Just change the name directly, if feasible
  // ******************************************
  GlobalStats.HighName[positionName] = entName;
}

function Start(){   
    HighScore();
}

function HighScore(){
    for(position = 0; position < GlobalStats.High.length; position++){
       if(switched == false && (GlobalStats.TotalScore > GlobalStats.High[position])){     // replace with new score
         positionName = position;
         switched = true;
         for(curPos = GlobalStats.High.length - 1; curPos > 0;curPos--){    // shift scores to the right
          GlobalStats.High[curPos] = GlobalStats.High[curPos - 1];

          // ***********************************************
          // We probably need to reorganize the names aswell?
          // ***********************************************
          GlobalStats.HighName[curPos] = GlobalStats.HighName[curPos - 1];
    
         }
         GlobalStats.High[position] = GlobalStats.TotalScore;
       }
    }

    GlobalStats.HighName[positionName] = entName;

    HighS1.text = GlobalStats.High[0].ToString();
    HighS2.text = GlobalStats.High[1].ToString();
    HighS3.text = GlobalStats.High[2].ToString();

    Name1.text = GlobalStats.HighName[0].ToString();
    Name2.text = GlobalStats.HighName[1].ToString();
    Name3.text = GlobalStats.HighName[2].ToString();
}