Global type arrays

BlitzMax Forums/BlitzMax Programming/Global type arrays

Tobs(Posted 2005) [#1]
Can someone tell me why this doesn't work?

Type MyType
Global ListArray:TList[100]
EndType

I'm doing this because I want to have an array inside the MyType namespace rather than in the global namespace.

Thanks


tonyg(Posted 2005) [#2]
Type MyType
Global ListArray:TList[]
EndType
mytype.listarray = New TList[100]

works but might not do what you want.


Tobs(Posted 2005) [#3]
that will work for now but this seems like a compiler bug?


skidracer(Posted 2005) [#4]
This has been fixed in next release.


Booticus(Posted 2005) [#5]
Cant you use

Field ListArray:TList[100]

??

Thats what I use for a TList in my Types.


taxlerendiosk(Posted 2005) [#6]
Booticus: He wants a single array for the type itself, not one array for each object of the type. Global instead of Field is the equivalent of a Function instead of a Method inside a type, if that's any help.


Tobs(Posted 2005) [#7]
That's right it's like a singleton.

What I'm doing is organizing things inside a type so they share the "MyType" prefix.

Hopefully the update will be here soon!


Garred(Posted 2005) [#8]
Try this:

Strict

Type MyType
	Global ListArray:TList[]
EndType

Type MyObject
	Field id%
End Type


' Creating lists
MyType.ListArray:TList = New TList[100]
For Local cont%=0 Until 100
	MyType.ListArray[cont%] = New TList
Next

' Adding objects
For Local cont%=0 Until 100
	Local a:MyObject = New MyObject
	a.id% = cont%
	MyType.ListArray[cont%].AddLast(a:MyObject)
Next

' Getting objects
For Local cont%=0 Until 100
	For Local a:MyObject = EachIn MyType.ListArray[cont%]
		Print a.id%
	Next
Next



Hotcakes(Posted 2005) [#9]
@skid, is this any relation to my problem at http://www.blitzbasic.com/Community/posts.php?topic=51880 ? It kind of almost seems like a reversed situation of what is here...