problem with lists

BlitzMax Forums/BlitzMax Programming/problem with lists

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.

I am trying to seperate the p1 and the p2 lists... I want p1 to contain values 0-10 and p2 to contain values 11-20. Running this code prints the following:

------------- p1 list -------------
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
------------- p2 list -------------
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


Here is the code:


Strict

Global p1:TParent
Global p2:TParent 

Type TParent
	Global list:TList
	Global child:TChild 
	
	Method New()
		If list = Null Then list = New TList 
		list.addlast Self
	EndMethod 
	
	Method destroy()
		list.remove Self 
	EndMethod 
EndType 

Type TChild
	Global list:TList
	
	Field val:Int 
	
	Method New()
		If list = Null Then list = New TList 
	EndMethod 
	
	Method destroy()
		list.remove Self 
	EndMethod 
EndType 	

For Local i = 0 To 10
	p1:TParent = New TParent
	p1.child   = New TChild
	p1.child.val = i
	p1.child.list.addlast p1.child 
Next

For Local i = 11 To 20
	p2:TParent = New TParent
	p2.child   = New TChild
	p2.child.val = i
	p2.child.list.addlast p2.child
Next 

Print "------------- p1 list -------------" 

For p1.child = EachIn p1.child.list  
	Print p1.child.val
Next 

Print "------------- p2 list -------------"

For p2.child = EachIn p2.child.list  
	Print p2.child.val
Next