I have several types which I would like to keep track of using lists. Since I'm trying to be modular and OOP, I'm trying to segregate the creation and maintenance of the list within the type and file. However, unless I declare the list as a Global variable in the main program loop/file, I'm getting errors. I'm trying to do something like the following:
Type creature
Field x#,y#
Field name:String = Null
Function Create(a#,b#,temp_name:string)
temp_creature:creature = new creature
temp_creature.x = a
temp_creature.y = b
temp_creature.name = temp_name
If CreatureList = Null Then Global CreatureList:TList = new TList
ListAddLast(CreatureList, temp_creature)
return temp_creature
End Function
End Type
I get an error with this because the first time through the IF statement is trying to access something that doesn't exist. I've also tried it with "If (not CreatureList)" too, but it still doesn't work. Do I declare the Global list in the type as a field (but wouldn't that create a new list with each new creature)? Any help would be appreciated!
|