global TYPE arrays

BlitzPlus Forums/BlitzPlus Programming/global TYPE arrays

Russell(Posted 2003) [#1]
Can anyone tell me why this array can not be seen in functions?:
; In main program:
Type Test
   Field active
End Type

Dim thing.Test(15)    ; Should be Global, right?
For a = 0 To 15
   thing.Test(a)   = New Test
   thing(a)\active = 1000
Next

Global thing2.Test = New Test  ; This one IS Global

Function Tester()
   DebugLog thing(0)\active   ; Prints 0!
End Function

Tester()


No errors are reported, but the Dim'ed type is not Global. What am I doing wrong?

And while I'm on the subject of Types, I know it's possible to create a Type that consists of other types, but I'll be damned if I can figure out how to do it (and that's not in the docs, either :( )

I thought this would do it:
Type Subtype
   Field x,y
End Type

Type MainType
   Field One.Subtype
   Field Two.Subtype
End Type


Am I doing something wrong here?

Thanks in advance!
Russell


Floyd(Posted 2003) [#2]
The first example displays 1000 in the debuglog.
But I had to add a Stop at the end so I could see it.

Your type within a type example should work.
Just remember that you still have to create the subtypes with New.
Graphics 250, 150, 0, 2

Type main
	Field n
	Field s.sub
End Type

Type sub
	Field x
End Type

Global m.main  ; now variable m exists, but does not point to an object

If m = Null 
	Text 10, 10, "m is Null"
End If

m = New main  ; m\n initialized to 0, m\s to Null

Text 10, 50, "m\n = " + m\n

; Here m\s is just a Null pointer...

m\s = New sub  ; now m\s actually points to an object

m\s\x = 12345

Text 10, 90, "m\s\x = " + m\s\x

WaitKey
End



Phil Newton(Posted 2003) [#3]
Works fine if you replace the "Debuglog" statement with a "Print" or whatever.

Types in types is easy too. Your example works fine. Just make sure you do the following when intialising your type:

temp.MainType = new MainType
temp\One.SubType = new SubType
temp\Two.SubType = new SubType


Pretty sure that covers it =)


Russell(Posted 2003) [#4]
Ah, that's it! I wasn't initializing the subtypes. But I'm still scratching my head on the first one, as my functions can't see the array'ed types I have set up. This worked perfectly in B2D, so there must be a subtle typo somewhere.

Thanks for the info, though. I'll have a closer look.

Russell