Array problem

BlitzPlus Forums/BlitzPlus Beginners Area/Array problem

The Forum Archive 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.

Here's an example for you... If you like kitties! lol

;Keep in mind that every variable of type kitty and person isn't ACTUALLY the kitty.  It's only a container variable (a.k.a. pointer) 
;that holds the kitty/person that exsits SOMEWHERE ELSE.  However, many variables can also hold the SAME kitty at the same time.  

SeedRnd(MilliSecs())
Type person ;Tell the computer what variables a container of type person holds
	Field kitties.kitty[99] ;this is just another way to declare an array, but it can be used inside of types.  The .kitty means that
							;this variable can hold other containers of type kitty (it can hold 99 kitties).  
	Field firstname$
	Field lastname$
	Field age
End Type

Type kitty ;Tell the computer what variables a container of type kitty holds
	Field colorofkitty$
	Field weightofkitty
	Field nameofkitty$
	Field id
	Field ownerofkitty.person ;this container can hold another container of type person.  
End Type

oldlady.person = New person ;create a new person that is held by oldlady
	;Tell the computer about oldlady.  Right now, all of the variables held by oldlady are empty.  
	oldlady\firstname$="Martha"
	oldlady.person\lastname="Love"
	oldlady\age=Rand(70,120)

For ICountkitties = 0 To 49 ;count to 50 kitties
	kitten.kitty=New kitty ;Create a new kitty
		kitten\Colorofkitty$=getrandomcolor$() ;get a random color for the kitty
		kitten\weightofkitty=Rand(3,20) ;get a random weight for the kitty
		kitten\nameofkitty=getrandomname$() ;random name
		kitten\ownerofkitty=oldlady ;set the owner of the kitty (which is another container) to oldlady
		oldlady\kitties[ICountKitties]=kitten ;Set one of the old ladies containers in the kitties type to the kitty we just made
		kitten\id=ICountKitties
Next

For thiskitty.kitty = Each kitty ;go through each and EVERY kitty that we have made so far, setting the container this kitty
										;to each as we go through them
	If thiskitty <> Null;Check to make sure the kitty exsits
		If thiskitty\ownerofkitty <> Null Then Print "Some old lady named " + thiskitty\ownerofkitty\firstname + " " + thiskitty\ownerofkitty\lastname + " has a(n) " + thiskitty\Colorofkitty + " kitty named " + thiskitty\ownerofkitty\kitties[thiskitty\id]\nameofkitty+"."
		;check to make sure that the kitty has an owner.  
		;after that notice that we can access the same variables as the 
			;oldlady variable used above by adding a \(variable) To thiskitty\ownerofkitty.  
		;We can take this a step further by adding \kitties[id] which is a pointer to other kitties.  That makes 
			;thiskitty\ownerofkitty\kitties[thiskitty\id] INTERCHANGABLE with thiskitty.  And just to prove this...
		If thiskitty=thiskitty\ownerofkitty\kitties[thiskitty\id] Then 
			Print "Print They're equal!  I win!"
		Else
			Print "Welp, I guess I'm just stupid, and wrong!"
		End If
	End If
Next

WaitKey()

Function getrandomcolor$()
	Select Rand(10)
	Case 0
		Return "Black"
	Case 1
		Return "Red"
	Case 2
		Return "Orange"
	Case 3
		Return "Green"
	Case 4
		Return "Blue"
	Case 5
		Return "Yellow"
	Case 6
		Return "Indigo"
	Case 7
		Return "Violet"
	Case 8
		Return "White"
	Case 9
		Return "Invisible"
	Case 10
		Return "Grey"
	End Select
	Return "*Non-existant*";This will never happen because all of the possibillities rand could put out have already been handled
							; and each of them returned (jumped out of) the function
End Function

Function getrandomname$()
	Select Rand(25)
	Case 0
		Return "Maggie"
	Case 1
		Return "Max"
	Case 2
		Return "Molly"
	Case 3
		Return "Lady"
	Case 4
		Return "Sadie"
	Case 5
		Return "Lucy"
	Case 6
		Return "Daisy"
	Case 7
		Return "Ginger"
	Case 8
		Return "Abby"
	Case 9
		Return "Sasha"
	Case 10
		Return "Sam"
	Case 11
		Return "Rocky"
	Case 12
		Return "Buster"
	Case 13
		Return "Casey"
	Case 14
		Return "Cody"
	Case 15
		Return "Duke"
	Case 16
		Return "Charlie"
	Case 17
		Return "Jack"
	Case 18
		Return "Harley"
	Case 19
		Return "Rusty"
	Case 20
		Return "Toby"
	Case 21
		Return "Murphy"
	Case 22
		Return "Shelby"
	Case 23
		Return "Sparky"
	Case 24
		Return "Barney"
	Case 25
		Return "Winston"
	End Select
	Return "BAD KITTY";Once Again, this will never happen
End Function