Another Minor Object Problem...

BlitzMax Forums/BlitzMax Beginners Area/Another Minor Object Problem...

po(Posted 2007) [#1]
Type TType

	Field x:Int
	
	Global List:TList=New TList
	
	Function Foo()	
	
		Local o:Object=List.Last()
		Local bar:Int=o.x
	
	End Function

End Type


When compiling it says identifier 'x' not found.
What would be the proper way to do this?


Perturbatio(Posted 2007) [#2]
You need to cast it as a TType
Type TType

	Field x:Int
	
	Global List:TList=New TList
	
	Function Foo()	
	
		Local o:TType=TType(List.Last())
		Local bar:Int=o.x
	
	End Function

End Type




Oddball(Posted 2007) [#3]
Edit: Ignore me I just posted completely the wrong thing. Sorry.


Grey Alien(Posted 2007) [#4]
Yeah those list functions only ever return an "Object" Type even though you may have stored another type in them. You always have to Typecast the return result when using Last, First and some other commands. You don't need to type cast if going:

For o:TType = eachin List



po(Posted 2007) [#5]
Ah. Thanks. I hate the fact that this sort of thing isn't documented.


Perturbatio(Posted 2007) [#6]
Help->Language->Types mentions casting an object into a derived type, but yes, the documentation could be clearer.