Question about Types (B3D)

Blitz3D Forums/Blitz3D Programming/Question about Types (B3D)

If you want a function to return a handle to an object (custom type), do this:
Function FindBuilding.building(id)
	For b.building = Each building
		If b\id = id Then Return b
	Next
End Function

; Find the building with id = 5
ABuilding.Building = FindBuilding(5)


The ".building" at the end of the function name states that the function will be returning a pointer (= handle) to a building-instance.

It's the same as having a function that would return a string:
Function GetFirstChar$(aString$)
	Local b$ = Mid$(aString$, 1, 1)

	Return b$
End Function


Here the "$" states that the function will be returning a string.


Really getting to grips with it now. How about this - is this legal? Will try later on but I'm at work now:

Type house
Field x, y, z
End Type
Global hse.house



Is the Global declaration okay?



This works, but you didn't create a house-instance yet.
The line "Global hse.house" just creates a global variable that is able to hold a handle to a house-instance, but the variable is still empty.
To create one, use this:
Global hse.house = New house