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 Ray Carter · Apr 18, 2011 at 02:35 PM · customsorting

Is not a memeber of Object

Hi, i have been going crazy with this. In the Star function when i try to reference the member name of my custom class, unity says name is not a member of 'Object'. Now i dont know when my custom object changed to Object type. Even when i debug the object, it says it is of type info. Only when i reference any member variable, it gives this error. Any help will be appreciated.

#pragma strict private var ObjectList :Array = new Array();

function AddObject(tname : String , tvalue : int){
var newinfo : Info = new Info(); newinfo.name = tname; newinfo.value = tvalue;
ObjectList.Add(newinfo); }

function SortObjects(thisObject : Info,thatObject : Info) {
if (thisObject.value < thatObject.value) { return 1; } else if (thisObject.value > thatObject.value) { return -1; } return 0; }

function Start(){

 AddObject("demo1",33);
 AddObject("demo2",66);
 AddObject("demo3",22);
 ObjectList.sort(SortObjects);
 Debug.Log(ObjectList[0]);
 Debug.Log(ObjectList[0].name);
 var temp : Info = new Info();
 temp = ObjectList[0];
 Debug.Log(temp.getName());

}

class Info { var name : String; var value : int;

 function getName(){
     return this.name;
 }

}

Comment
Add comment · Show 4
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 robertmathew · Apr 18, 2011 at 02:44 PM 0
Share

arrange it properly

avatar image FLASHDENMARK · Apr 18, 2011 at 02:54 PM 0
Share

Next time please highlight your code and press the "10101" button. It will give you a nice and readable code.

avatar image Jessy · Apr 18, 2011 at 02:55 PM 0
Share

Use a List ins$$anonymous$$d of an Array; Array is obsolete.

avatar image Ray Carter · Apr 19, 2011 at 06:03 AM 0
Share

But how do i use List in this case? I am kind of new to jscript and unity. But i added import System.Collections.Generic; and initialised a List but it says unknown keyword List. Can you explain how will i do that? thanks.

1 Reply

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

Answer by Mike 3 · Apr 18, 2011 at 02:57 PM

The problem is that Array isn't typed - everything that goes in there gets stored as a System.Object reference

What you could do instead is use a List.< Info> instead, which requires you to add import System.Collections.Generic; to the top of your script

For more info on that, http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

Just remember to use a . before the < each time :D

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 Ray Carter · Apr 19, 2011 at 06:22 AM 0
Share

Hi, can you explain how do i accomplish that?

avatar image Ray Carter · Apr 19, 2011 at 09:44 AM 0
Share

Thanks i found it. var ObjectList : List.; and i had to replace ObjectList.sort to ObjectList.Sort.

Thanks a bunch!

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

No one has followed this question yet.

Related Questions

Custom sorting function - need help 2 Answers

Can I use my own input device? 4 Answers

How to call a custom object from a C# dll 1 Answer

Editor Window with settings and Asset Creation 1 Answer

Creating an asset from script? 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