Tlists containing different types

BlitzMax Forums/BlitzMax Programming/Tlists containing different types

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You need to "typecast" the plain Object into the actual object type that it is so that the name will be recognised. E.g.

For Local loop:Object=EachIn Test
	If ttesta(loop) Then Print ttesta(loop).name
	If ttestb(loop) Then Print "B"
Next


Maybe a better method would be to define a base class with an ObjectType field that you can set to a value. Then extended the base class for all your other classes. Then inside the For loop you can simple typecast the loop object as your base class type and then check the ObjectType field before calling specific actions. However, it would be best for something like Draw() of the bass class had a Draw() method that you override in the extended classes, so whenever you call the Draw() it calls the correct one. This is called Polymorphism and I probably have not explained it very well if you don't already know about it...