Guest User

Untitled

a guest
Jan 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function LoadStats(){
  2.     //try to read the SaveFile
  3.         try {
  4.  
  5.         //gets the last Loaded file witch is stored in the registry
  6.             FilePath = PlayerPrefs.GetString("LastLoadedFile");
  7.  
  8.             sr = new StreamReader(FilePath);
  9.         var fileContents = sr.ReadToEnd();
  10.  
  11.            
  12.  
  13.             //print("fine:for splitting"); debugging statement
  14.             lines = fileContents.Split(["\n"],System.StringSplitOptions.RemoveEmptyEntries);
  15.            
  16.             //print("fine:for print loop"); debugging statement
  17.             for(var i=0;i<lines.Length;i++){
  18.            
  19.                 var data:String[]  = lines[i].Replace(";","").Split(["="],System.StringSplitOptions.RemoveEmptyEntries);
  20.                
  21.                 var name:String = data[0];
  22.                 //print("names" +data[0]); debugging statement
  23.                 //print("values"+data[1]); debugging statement
  24.                 //Debug.Log("Isworking" + data[1]); debugging statement
  25.                 //Debug.Log(data[1].Substring(0, 1)); debugging statement
  26.                 if(data[1].Substring(0,1)!="\""){
  27.                     values = parseInt(data[1]);
  28.                     //Debug.Log(name + "->" + values);
  29.                     var index: int = FindIndex(StatNames, name);   
  30.                     print(index);
  31.                     if(!(index==-1)){
  32.                         CurValue[index]=values;
  33.                         //Debug.Log("got here");
  34.                     }          
  35.                 }
  36.                
  37.                 if((data[1].Substring(0,1)=="\"")){
  38.                     data[1] = data[1].Replace("\"","");
  39.                     //this line replaces the " symbol
  40.                     //print(data[1]);
  41.                     PlayerName=data[1];
  42.                     //More Sorting Parameters Here
  43.                     //data[1] = data[1].Replace(".");              
  44.                 }
  45.    
  46.             }
  47.    
  48.         }
  49.  
  50.         catch (e) {
  51.             // Let the user know what went wrong.
  52.             print("The file could not be read:");
  53.             print(e.Message);
  54.             return;
  55.         }
  56.  
  57.  
  58.  
  59. }  
  60.  
  61. function FindIndex(list:String[], name:String):int {
  62.  
  63.  
  64.     //return list.IndexOf(list,name);
  65.    
  66.     for (var i:int=0; i<list.Length;i++) {
  67.         if (list[i] == name) return i;
  68.     }
  69.     return -1;
  70. }
Add Comment
Please, Sign In to add comment