types in types

Blitz3D Forums/Blitz3D Programming/types in 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 could easily achieve it like this :

Type forest
	Field forestname
End Type

Type tree
; new :
	field treeforest.forest  ; holds the forest that the tree belongs to
; end new
	Field treetype$
End Type

Global f1.forest=New forest
Global f2.forest=New forest

; new
f1\forestname="green forest"
f2\forestname="brown forest"
; end new


;make 5 trees in forest 1 and mark them as "green"
For a = 1 To 5
; changed :
	t.tree = New tree
	t\treetype$ = "green"
; end changed
; new
	t\treeforest=f1
; end new
Next


;make 5 more trees, but in forest 2 this time and mark them as "brown"
For a = 1 To 5
; changed :
	t.tree = New tree
	t\treetype$ = "brown"
; end changed
; new :
	t\treeforest=f2
; end new
Next


;now to make my point when looping through the trees in forest 1, there should be no "brown"
;yet it goes through all trees.........anyone know how to go around this/or am i doing something wrong?
;should it look like this somehow in the for loop ?
;For f2\t = Each f2\t.tree   ???? or
;for f2\t = Each tree in f2

; changed :
For t.tree = Each tree
	if t\treetype$="brown" then Print t\treetype$
Next
; end changed

WaitKey




Or use [] arrays within the types.