Map Container used for multiple Instances
Monkey Forums/Monkey Programming/Map Container used for multiple Instances
| ||
I have two questions. I am wondering if i can use an IntMap, or another Container to hold multiple Instances of a variety of Classes. Right now i have something like this. Maybe i am going about this the wrong way. But what i would like to do is have different classes that inherit UnitBase and store them in my IntMap. Say a Class for a Zombie, and then a class for a Orc, ect. That way all of my instance for the monsters in the game are stored in a single container. Also when i create and Instance i notice that OnCreate() is not run. Thanks. |
| ||
Wait. I can use a variety of IntMaps, one for each Class i would like to store, and contain the IntMaps inside a StringMap. I think... I would still like some feed back in case i am overthinking or underthinking what i am trying to do. Thanks. |
| ||
Hi, Use inheritance to store multiple 'subclasses' of a class in the same container, eg: Class Unit Method Update()...blah End Class Zombie Extends Unit Method Update()...blah End Class Pixie Extends Unit Method Update()...blah End Global Units:=New IntMap<Unit> Function Etc() Units.Set 0,New Unit Units.Set 1,New Zombie Units.Set 2,New Pixie End 'Extends' means that a class 'is a kind of' some other class, so you can use it whether the other class is expected. Also, use Method New() to construct objects - OnCreate() is just for the Mojo App. |
| ||
Got it, thanks allot! |