Types, room.chair

Blitz3D Forums/Blitz3D Beginners Area/Types, room.chair


So if I use a function and return whole type entry, how do I then access the fields in that returned entry?



Type chair
	Field Name$
	Field Height
End Type

Global room.chair

; Create a new chair type-instance, set it's name and return it to the variable "room"
room = CreateChair("Nice chair")
room = CreateChair("Bad chair")

For room = Each chair
	Print room\Name
Next

WaitKey()


Function CreateChair.chair(Name$)
	Local a.chair = New chair
	a\Name=Name$
	Return a
End Function


Here the creation of a chair type-instance and settings it's name is done within the function CreateChair, which returns the chair as a type-instance and gives it to the variable "room".
Afterwards, you can access the room's fields the same way as if you had created the type-instance in the main code.