List and Class
Monkey Forums/Monkey Programming/List and Class
| ||
Hello, In Blitzmax we can write an estructure like this: Type Tobj field x : float field y : float ... End Type ... and to create derived types: Type Tplayer extends Tobj ... End Type Type Tenemy extends Tobj ... End Type Suppose we have added all the objects created to a list called myList. BlitzMax access all the objects added to the list in this way: For o : Tobj = Eachin myList ..... Next If you want to access Tplayer objects we can wrote: For o : Tplayer = Eachin myList .... And if we access the Tenemy objects we can wrote: For o : Tenemy = Eachin myList ---------------------------------------------------- In Monkey, we create the base class: Class Tobj .... End ' Tobj And after that, the derived classes: Class Tplayer extends Tobj .... End ' Tplayer Class Tenemy extends Tobj ..... End ' Tenemy To access to all Tenemy and Tplayer objects .... Local myList := New List <Tobj> For Local o := Eachin myList o.render() Next ... but, here is my question. How can I access from Monkey to all Tenemy objects only? For local o ... ? Thank and kind regards, Tagoror |
| ||
You can promote the object inside the loop. For Local o ... If tEnemy(o) Then 'Its of tEnemy Else ' its not Endif Next I'm not sure if all the target languages support the type of casting that BMax eachin does. |
| ||
All target languages, but take into account that Arrays ore Strings are not objects in Monkey. |
| ||
Thank you for the information. I'm going to test it. |