- Home /
Question by
Leepo 1 · Nov 25, 2010 at 10:32 PM ·
javascripttypepragmastrict
How to foreach a typed list in Strict Unityscript
With this list in place:
List.<FPSChatEntry>();
The following for (foreach..) causes an error:
for (var entry : FPSChatEntry in
chatEntries) {
}
Error:
Cannot convert 'Object' to 'FPSPlayerNode'.
How can this be done in US/Javascript?
Comment
Answer by starkos · Apr 05, 2012 at 12:18 PM
This works for me, in Unity 3.5
class CharacterMotionState {
var name:String;
}
var motions : List.<CharacterMotionState> = new List.<CharacterMotionState>();
for (var motion:CharacterMotionState in this.motions) {
// ...
}
I think there is some other error in your code. Your loop is looking for FPSChatEntry objects, but the error seems indicate that an FPSPlayerNode is needed. Have you strongly typed chatEntries?
Your answer
![](https://koobas.hobune.stream/wayback/20220613084549im_/https://answers.unity.com/themes/thub/images/avi.jpg)