- Home /
Highscore error when comparing int with array
Hi there, I'm working on a local highscore in my sidescroller game, but I don't know how to fix this error. Can anybody help me with this code?
static var newHighscore : boolean = false;
static var dead : boolean = false;
private var nameEntry : boolean = false;
private var newHighscoreRank : int;
private var highscoreName = Array(String);
private var highscore = Array(int);
private var names : String;
private var scores : int;
var newScore : int = 0;
var newName : String = "Player1";
highscore.length = 10;
highscoreName.length = 10;
for (i=0;i<10;i++) {
if (PlayerPrefs.HasKey(i+"Scorename")) {
newScore = PlayerPrefs.GetInt(i+"Score"); newName = PlayerPrefs.GetString(i+"Scorename"); } highscore.Add(newScore); highscoreName.Add(newName);
if (dead) {
if (scores > highscore[i]) {
newHighscore = true; newHighscoreRank = i; if (nameEingabe) {
for (j = i+=1; j < 10 ; j++) {
highscore[j] = highscore[i]; highscoreName[j] = highscoreName[i]; } highscore[i] = scores; highscoreName[i] = names; } }
PlayerPrefs.SetInt(i+"Score",highscore[i]); PlayerPrefs.SetString(i+"Scorename",highscoreName[i]); } } }
When I run the code it returns this error:
MissingMethodException: Method not found: 'System.Int32.op_GreaterThan'. Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher () Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create () Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey12.<>m_6 () Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) Rethrow as MissingMethodException: Greater than is not applicable to operands 'System.Int32' and 'System.MonoType'. Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) Platformen.AddScore () (at Assets/Assets/Scripts/Platformen.js:70) Platformen.OnGUI () (at Assets/Assets/Scripts/Platformen.js:132)
line 70 is where it says 'if (scores > highscore[i]) {'
Does anybody of you know how to fix this?
Thanks! ;)
Answer by DaveA · Jul 27, 2012 at 12:06 AM
Try taking the 'int' out of new Array (int) and use new.
private var highscore = new Array();
and actually, you should do the 'new' in Start:
function Start()
{
highscore = new Array();
I changed the code to:
private var highscore; function Start () {
highscore = new Array(); }
but that didn't fix the problem.
The only other thing I can think of is the index i is out of bounds (either less than zero or more than the number of elements in highscore array.
Answer by Holzkohle · Jul 27, 2012 at 09:19 AM
I tried, but now it says:
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) Platformen.AddScore () (at Assets/Assets/Scripts/Platformen.js:70) Platformen.OnGUI () (at Assets/Assets/Scripts/Platformen.js:132)
Thanks for answering! ;)
Please use 'comment' not 'answer' unless answering your own question. I have edited my answer, please see above
Your answer
Follow this Question
Related Questions
Comparing two objects properties for the closest 0 Answers
Boo: Object reference not set to an instance of an object 1 Answer
Compare Contents of arrays 2 Answers
Unity C# Highscore table 2 Answers
FindGameobjectsWithTag -> Array 2 Answers