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 Itinerant · Mar 13, 2013 at 05:41 PM · javascriptstringloops

Problem with looping concatenation with custom class

I have an array of objects, a custom class that has an attribute called 'commentUID.' I'm trying to output a string that combines the commentUID of each object with a comma in between. However, my script won't add anything past the first object, and I have no idea why. It's running through the loop...it's just not adding the commentUID strings. If I try it with another type of object, like have it add a simple string, it works as expected. Any ideas?

 var allComments : commentObj[] = new commentObj[0];
 
 class commentObj { 
 
     //Use this number to assign the Alr
     private var projectID : int = 1;
 
     var commentUID : String;
 
     var user : userInfo;
     var userPos : userPosition;
     
     var target : GameObject;
     var targetPosition : Vector3;
     
     var view : Texture2D;
     var date : System.DateTime = System.DateTime.Now;
     var text : String;
 }
 
     var CommentString : String;
     
     for (var x = 0; x<allComments.Length; x++){
         if(x == 0){
             CommentString = allComments[x].commentUID;
             Debug.Log("Ran Once");
         }
         else{
             CommentString = CommentString + "," + allComments[x].commentUID;
             Debug.Log("Ran " + (x+1) + " times");
         }
     }
Comment
Add comment · Show 2
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 Itinerant · Mar 13, 2013 at 05:42 PM 0
Share

I'll note that I've tried this using CommentString += allComments[x].commentUID as well.

Also, as is probably obvious, this isn't the full script - I've only included the relevant parts, not the parts that create commentObjs or add them to the allComments array. Those parts work fine.

avatar image Itinerant · Mar 13, 2013 at 05:51 PM 0
Share

Yeah, I remembered that I'd swapped that out and commented about it above. I've tried this with two formats:

x += y; x = x + y;

Neither one works...each time I end up with my original x, without the y concatenated to it.

edit: this was a response to a now-deleted comment

1 Reply

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

Answer by Itinerant · Mar 13, 2013 at 07:43 PM

Ok, so it looks like it was a problem with the input....I'm not really sure what caused it, though. It was typed to a String, so I wouldn't expect problems. In any case, fortunately my commentUID (while I treat it like a String) is actually purely numerical. I was able to fix my problem by changing the allComments.x.commentUID into parseInt(allComments[x].commentUID).ToString()

Why this works, I can't really say. Something is obviously wrong with my input, but darned if I know what :P

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

11 People are following this question.

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

Related Questions

String Problem in Java Script 1 Answer

Combo Script Problem 1 Answer

How to convert a float to a string and then have it appear in a gui rect 3 Answers

How you can start the animation of an object as finished another ? 0 Answers

Unable to use parameter in javascript. 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