Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 skwunk · Aug 19, 2015 at 02:17 AM · arrayplayerprefsx

Trying to get an array to show up in Debug.log

I'm trying to script a high score table that could be saved in PlayerPrefsX for my game project, but I can't seem to get the int array that I created for it to even show up in Debug.Log (or anywhere else really) even after creating a test value to see if anything is even being entered. Not even the Inspector shows any indication that anything happened, all of the values show up as 0. Here's the chunk of code I have for it so far:

 var scoreArray = new int[8];
 var testScore:int = 1000;
 var i:int;
 var j:int;
 
 function Start () {
 
 }
 
 function Update () {
     
     for (i = 0; i > 8; i++) //high score check
         {
             if (testScore > scoreArray[i])
             {                        
                 for (j = scoreArray.length - 1; j <= i; --j ) //pushes the score values down starting from the slot that testScore ends up
                 {
                    scoreArray[j] = scoreArray[j-1];
                 }
                 
                 scoreArray[i] = testScore;
             }
             
             Debug.Log(scoreArray[i]);
         }
 
 }

I prefer solutions in JS as that is the language that I have the most experience with.

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
1
Best Answer

Answer by Bakshish-Singh · Aug 19, 2015 at 05:01 AM

I think there is some problem with your code you posted. The for loop on line 12 should be

 for (i = 0; i < 8; i++) //high score check

rather than

  for (i = 0; i > 8; i++) //high score check

The ">" should be replaced with "<"

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 skwunk · Aug 20, 2015 at 04:55 PM 0
Share

You're right, I had my operators flipped. Thanks, I guess it helps to have another set of eyes to look at the code to catch something like that. :)

avatar image
1

Answer by arun.pandey89 · Aug 19, 2015 at 03:24 AM

There are few loop holes .

1) Break the loop as soon as you get any index which has lesser value then high-score (Coming from top to bottom). Why traverse bottom numbers they are definitely smaller as compared to high-score and not your concern.

2) While breaking loop sort array based on new high-score .Also your re-arranging array logic is not correct . try this :

 for (j = scoreArray.length - 1 ;  j > i ;  j-- )
                                       scoreArray [j] = scoreArray [j - 1];

Cheers Arun

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 skwunk · Aug 20, 2015 at 04:51 PM 0
Share

Thanks so much, I didn't realize that I could use break to stop a for loop once it finds a value lower than the testScore. I also fixed my sorting logic to properly count down the array and moved the whole loop to the Start function and now it works the way I want it to.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Store Array in PlayerPrefX in Unity JS 1 Answer

assigning arrays with for in 1 Answer

Attempting to store an Inventory Array in PlayerPrefsX 1 Answer

Saving Array Objects in Android. 0 Answers

PlayerPrefsX Question 1 Answer


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