Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Holzkohle · Jul 26, 2012 at 11:33 PM · errorarraycomparehighscore

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! ;)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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();
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Holzkohle · Jul 28, 2012 at 07:49 PM 0
Share

I changed the code to:

private var highscore; function Start () {

highscore = new Array(); }

but that didn't fix the problem.

avatar image DaveA · Jul 30, 2012 at 08:44 PM 0
Share

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.

avatar image
0

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! ;)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Jul 27, 2012 at 10:19 PM 1
Share

Please use 'comment' not 'answer' unless answering your own question. I have edited my answer, please see above

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges