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 COLLAnitySV · Jan 13, 2012 at 01:37 PM · arrayplayerprefsbooleanfor-loopplayerprefsx

For In Loop Fills all values in arrays problem

Return from my past questions... I have a problem with assigning values on unassigned array values. When i'm trying to make for in loops, the script assigned same values on all arrays. Now my question is, how to make the script just assign one values in an array and then it will assign another values later.

This script i use for assigning 'used' values on an arrays, so if one objects exploded it will assign just one 'true' on one array, not all arrays.

This is my script. it's simplified.

rs is RegSaver.js, usedObj is Boolean[], isExploded is boolean (used when an object exploded), and RegisterThis Function added in function Update if the object has exploded (if(isExplode) RegisterThis)

 function RegisterThis(){
     for(var i : int = 0; i < rs.usedObj.length; i++){
         if(isExploded && rs.usedObj[i] == true){
             rs.usedObj[i] = isExploded;
         }
     }
 }

I hope it's not too hard. Thanks for the answer. i really need this script

alt text

Comment
Add comment · Show 3
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 syclamoth · Jan 13, 2012 at 01:44 PM 0
Share

I'm sorry, I really don't understand the question. Can you reword it? What, exactly, do you want this function to do?

avatar image COLLAnitySV · Jan 13, 2012 at 01:52 PM 0
Share

oh i'm sorry... what i want to do is assigning just one value in an array (i had a problem, it's assigning all same value in an array)

avatar image syclamoth · Jan 13, 2012 at 02:40 PM 0
Share

'one value', 'all the same value'- to me, these are talking about the same thing.

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by BiG · Jan 13, 2012 at 02:16 PM

I'm not sure at all yet on what you are trying to implement, COLLAnitySV, but I would try to give you an answer. Sorry if it will miss your intentions.

"When i'm trying to make for in loops, the script assigned same values on all arrays"

First of all, I think that you are messing up some terminology: when you talk about "arrays", you are thinking about "array's elements", don't you? Because you just have a single array, that's usedObj.

Then, I think that you want enable these array's elements one at a time, in an incremental way. In that case, you have to hack "i" variable to directly skip the remaining iterations of the loop:

function RegisterThis(){
    for(var i : int = 0; i < rs.usedObj.length; i++){
       if(isExploded && rs.usedObj[i] == true){
         rs.usedObj[i] = isExploded;
         i = (rs.usedObj.lenght) + 1;
       }
    }
}

I repeat, I've many doubts about the desired behaviour of your script. Sorry if I miss that.

Comment
Add comment · Show 4 · 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 syclamoth · Jan 13, 2012 at 02:40 PM 0
Share

Can't you use 'break' to break out of a for-loop?

avatar image BiG · Jan 13, 2012 at 02:45 PM 0
Share

Yes, you can. I was not sure about that possibility in UnityScript.

avatar image COLLAnitySV · Jan 13, 2012 at 02:59 PM 0
Share

Thanks! It's really work!!! but i got this message : 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)

avatar image BiG · Jan 13, 2012 at 03:53 PM 0
Share

I've just done a short research about your error, but, unfortunately, I can't help you (if that's an iPhone project, maybe you could look here: http://forum.unity3d.com/threads/69998-Strange-Array-problem, but that is an old post, and I'm not sure that it could help you so much)...

However, the fact that my solution works, it's a confirmation of the fact that your code is, in some manners, a lil' messy! Because my solution isn't "elegant" at all! __

As an advice, think on the possibility to implement @Larry Dietz's solution, under this one (+1 to him, BTW!) If you can do it, I think that your last problem will be gone.

Good luck, and let us know if you have other troubles.

avatar image
2

Answer by Larry-Dietz · Jan 13, 2012 at 02:16 PM

I may be misunderstanding the question, but if you only want 1 element set to true, why use a loop to loop through all elements of the array? Why not just pass the index that you want set? Something like this...

 function RegisterThis(var i){
     if(isExploded && rs.usedObj[i] == true){
        rs.usedObj[i] = isExploded;
     }
 }

-Larry

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

assigning arrays with for in 1 Answer

How to save an array to PlayerPrefs? 1 Answer

How to Get a PlayerPrefsX boolean? 1 Answer

bool array to playerprefs 1 Answer

Saving Array Objects in Android. 0 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