- Home /
Object reference not set to an instance of an object help (JS)
Hi all,
Here is my code that checks to see a if a int variable is between different ranges by using if statments.
There's probably a more elgant way of doing this but the error I am getting is an NullReferenceException: Object reference not set to an instance of an object. I know this error means it can't access something vital but in the inspector everything is enabled and the scripts are connected with game objects. Here is my code and a screenshot to prove that.
function Start(){
if (File.Exists(fileName))
{
var sa = new StreamReader(fileName);
var fileContents = sa.ReadToEnd();
scorecounter.text = fileContents.ToString();
sa.Close();
var intfilecont = fileContents.parseInt; //error happens here
if (intfilecont > 0 && intfilecont < 21){
comment.text = "POTATOE Damn son, invest in a better PC";
}
if (intfilecont > 19 && intfilecont < 31){
comment.text = "BRONZE git gud m8";
}
if (intfilecont > 29 && intfilecont < 41){
comment.text = "SILVA Your PC is c00l and g00d";
}
if (intfilecont > 39 && intfilecont < 51){
comment.text = "G0LD Wow! very nice mate";
}
if (intfilecont > 49 && intfilecont < 69){
comment.text = "PLATINUM YO IS YOUR PC LIT? like is it literally on fire now?";
}
if (intfilecont == 69){
comment.text = "MLG You must be the luckiest quick scoper to live m9";
}
if (intfilecont > 69 && intfilecont < 90){
comment.text = "SUPER SAIYAN to go even further beyond!";
}
if (intfilecont > 99){
comment.text = "NASA wtf do you have a super computer?";
}
}
}
![alt text][1]
There is more code above this that isn't attached to the problem if you were wondering.
I don't know what is happening and would appreciate any help.
[1]: /storage/temp/100758-proof.png
Follow this Question
Related Questions
Hi I get an error code when i'm using my Javascript and I can't understand how to fix it... :( 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer
[js]NullReferenceException: Object reference not set to an instance of an object 1 Answer
What is wrong with my script? 1 Answer