Basic Nested Types Demo

Tweet blitz3d blitzbasic code-archives miscellaneous rated
(Posted 1 year ago) RonTek

snippet example showing how to use nested types or deriving from base types/class

Graphics 800,600,0,2

SeedRnd MilliSecs()

Type vehicle
    Field id
    Field year
    Field type_$
End Type

Type car
    Field auto.vehicle
    Field model$
    Field transmission$
End Type

Type plane
    Field jet.vehicle
    Field model$
    Field propulsion$ 
End Type

For i = 1 To 2 = New car
    street\transmission$ = "Manual"
    street\auto = New vehicle
    street\auto\year = Rnd(8)+2010
    street\auto\type_$ = "Sports"   
    street\auto\id = Rnd(1000)+20000

For i = 1 To 2  
    military.plane = New plane
    military\propulsion$ = "Gas Turbine"
    military\jet = New vehicle
    military\jet\year = Rnd(10)+1990
    military\jet\type_$ = "Fighter" 
    military\jet\id = Rnd(1000)+20000

; show plane types only which has a unique field propulsion$ and a base/common field (id and year)

Print "Jets Only"
Print "========="
For fighter.plane  = Each plane
 Print fighter\jet\id + ": " + fighter\propulsion$  + " ("+fighter\jet\year+")"

Print ""

; show all vehicle objects created which we can access the base/common fields (id, year and type_$)

Print "All Vehicles"
Print "============"
For all.vehicle  = Each vehicle
 Print all\id+ ": " + all\type_$ + " ("+all\year+")"

Until KeyHit(1)

Reply To Topic (minimum 10 characters)

Please log in to reply