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 dansav · Feb 29, 2012 at 06:55 PM · objectlistclasshashtablepragma

Can I make a list of hashtables or classes with pragma strict

I'm trying to make a list of hashtables but I am getting errors

   pragma strict
 var animations=new List.<Hashtable>();  
         
         function CreateHash(i){  
         animations[i]["name"]="firsthash";  
         animations[i]["rotations"]=new List.<Vector3>();  
         }
 

when I try to use the hashes list I get errors like hashes[0]["rotations"].Count --count is not a member of object etc... Is this because it doesn't know what rotations is because it is not declared outside of the function?

Is there a better way to go about doing this. The basic idea is to have an animation that hold many different properties? Should I create a class instead?

Can I make a list of classes? can I do animations=List.() if animation is a class?

Thanks,

Comment
Add comment · Show 1
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 dansav · Feb 29, 2012 at 07:00 PM 0
Share

I'm trying to block the code with the code button but it still is hiding things like the tagscripttag for the list? so the code is not displaying correctly. It looks okay in the preview but then enlarges pragma strict and ignores all the code blocking.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by BetaWar · Feb 29, 2012 at 09:11 PM

That error is likely because the hash table stores its entries in a String => Object (string to object) association, so you get getting an object back from the hashes[0]["rotations"] and then trying to access a list variable.

Try something like so:

(hashes[0]["rotations"] as List).Count

You basically just have to remember to cast things as you go to ensure the compiler knows what you are using at any given point.

Hope that makes sense.

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
avatar image
0

Answer by steinbitglis · Feb 29, 2012 at 08:17 PM

Well, Hashtable will store objects of type Object, if you don't declare anything else. So it will accept both strings and lists, as you show, but it will not be able to find the type of anything stored until runtime.

You could declare a specific type of Hashtable if you need to, unless my assumptions about unityscript are wrong. var animations = new List.<Hashtable<string, List<Vector3>>>();

I would seriously consider if this stuff is really necessary.

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

6 People are following this question.

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

Related Questions

Removing a class object from a list(.remove not working) C# 1 Answer

How do I Create 5 Random Racers? 2 Answers

How to store a class as a variable 1 Answer

A node in a childnode? 1 Answer

JS to C# List type problem 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