- Home /
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,
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.
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.
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.
Your answer
Follow this Question
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