- Home /
How to use an Array list of classes inside a class?
I have a class Map, that has an array of classes Platform inside. My problem is when trying to access the information in the platform class I get this error:
BCE0019: 'ID' is not a member of 'Object'.
Here is the code:
class Platform {
var ID : int;
function Platform( thisID : int ){
ID = thisID;
}
}
class Map {
var platforms = new ArrayList();
}
var thisMap = new Map();
thisMap.platforms.Add(new Platform(1));
//Now if I try to access this information I recieve the error:
Debug.Log(thisMap.platforms[0].ID);
I'm not sure why I'm getting this error and couldn't find anything on the internet so any help would be great!
Answer by robertbu · Jun 16, 2013 at 03:53 PM
It is a typing issue you could get around by casting. But I recommend using a generic list instead
class Map {
List<Platform> platforms = new List<Platform>();
}
In addition, you will have to do as @kilian277 suggests and make ID public.
Great thanks changed it to generic lists and worked perfect :D
Your answer
Follow this Question
Related Questions
How to find the opposite variables list? 1 Answer
Inspector variable MonoScript, using for creating a List? 2 Answers
Shotgun using array/list in Javascript 1 Answer
How to put buttons in a list? 1 Answer
Storing functions in a list/array? 1 Answer