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 JeanetteKLDK · Dec 26, 2012 at 07:33 PM · arraynetworkcompareip

Changed array type, different functions?

Hi Forum!

EDIT: I have changed approach to how I create arrays, for my server, and apparently this given me severe problems. I now use the layout of the template chatroom by Unity, with this approach:

 class Server_Clientlist_Entry
 {
     var text = "";    
     var Style = 1;
 }

 function Server_Clientlist_Add (str : String, Style : int)
 {
     var entry = new Server_Clientlist_Entry();
     entry.text = str;
     Debug.Log(entry);
     if (Style == 1) entry.Style = 1;
     if (Style == 2) entry.Style = 2;
     if (Style == 3) entry.Style = 3;
     if (Style == 4) entry.Style = 4;
     if (Style == 5) entry.Style = 5;    
         
     Server_Clientlist_Entries.Add(entry);
     Server_Clientlist_ScrollPosition.y = 1000000;    
 }

This gives me a problem. For some reason, when I try to add lines with this, it prints them right onto the screen, but it stores the name of the class "Server_Clientlist_Entry" in the array, and not the actual string, so I can't e.g. print or search compare to any index, since all index values are apparently "Server_Clientlist_Entry" .. Maybe this is since it uses a class, but how do I avoid this? I want to be able to loop through the index, and check if an entry with the same name already exist. This is an edited thread as I learned more from debugging.

Thanks in advance for your time, Jeanette

Comment
Add comment · Show 6
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 JeanetteKLDK · Dec 26, 2012 at 09:01 PM 0
Share

Okay, after various document lookup-reading I narrowed the error. When I try to use this approach, for some reason it prints the correct input into the chatlines on the screen, after having debugged the variable "entry" it appears that what happens is it doesn't actually store the text I pump into the chat in the array, but just stores the name "Server_Clientlist_Entry" in each line of the array, why is that, what is wrong with my code above. I mean, it prints the right thing out, it it due to the fact that it also uses a class?

 class Server_Clientlist_Entry
 {
     var text = "";    
     var Style = 1;
 }
avatar image whydoidoit · Dec 26, 2012 at 09:36 PM 0
Share

What is Server_Clientlist_Entries this a list of? Can you post the definition?

avatar image JeanetteKLDK · Dec 26, 2012 at 10:49 PM 0
Share

It is just defined as a variable, with the actual array.

private var Server_Clientlist_Entries = Array();

avatar image whydoidoit · Dec 26, 2012 at 10:50 PM 0
Share

You want to use a

      List.<Server_Clientlist_Entry>
avatar image JeanetteKLDK · Dec 26, 2012 at 11:06 PM 0
Share

Not sure how that works, isn't list a strict C#? This is coded entirely in Java. Not sure how this would make me able to lookup individual strings of the index. As I see it, the problem isn't looking them up, since they ARE there, but it doesn't actually store the right thing in them, in the first place.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 26, 2012 at 11:40 PM

First like Mike said you should use a List instead of an Array. The Array class does the same thing but with untyped content. A generic List is strong typed and therefore is faster and type safe.

I guess your actual problem is the place where you access / display your items. I'm pretty sure you have something like that:

     GUI.Label(..., Server_Clientlist_Entries[some index]);

But you have to access the string like this:

     GUI.Label(..., Server_Clientlist_Entries[some index].text);

You just use the class reference like a string so it returns the class name. You actually want the string that is stored in the text variable of that class.

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

Array index out of range? 3 Answers

Compare Contents of arrays 2 Answers

How do I find a String in an Array? 2 Answers

Take only one action ~ if(A = var[i]) reveals a true 1 Answer

Calling System.Net.Dns.GetHostEntry(sHostName) failed 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