Nesting Type

Blitz3D Forums/Blitz3D Beginners Area/Nesting Type

mag.(Posted 2003) [#1]
Could we make a Nesting Type
Could someone give some simple example on that


NTense(Posted 2003) [#2]
Type Player
   Field ObjectHandle
   Field xPosition#
   Field yPosition#
   Field zPosition#
   Field PlayerWeapon.Weapon
End Type

Type Weapon
   Field Name$
   Field ObjectHandle
   Field Damage#
   Field FireRate
End Type

Player.Player = New Player
Player\PlayerWeapon.Weapon = New Weapon

Player\xPosition# = blah,blah,blah
Player\PlayerWeapon\name$ = blah, blah, blah


You can nest as many levels as you like
Hope this helps a little.


mag.(Posted 2003) [#3]
Thanks NTense. Its help a lot


Gabriel(Posted 2003) [#4]
Be aware that nested types are not "truly" nested. That is, using the above example. If you create three players, and 2 weapons for each of them, when you cycle through all the weapons with For.. Each you will be cycling through all six weapons. There is no command to specifically cycle through only those that correspond to a particular player.

For that you will need to add a parent field which stores the type handle of the player who owns the weapon.

Of course, in the example given, you probably won't need any of this. But in other cases of nested types, you will need to know the "parent" of the "child" type instance.


soja(Posted 2003) [#5]
Clarification: Sybixsus is referring to the internal linked list of type instances. So, to distinguish, all of the actual custom type *objects* are in a linked list, whereas the custom type *pointers* can be nested within other custom types. (And type pointers are what you work with as members of other types.)


EricZann(Posted 2003) [#6]
Is there a way of having an *array* of types inside another type? This sort of thing (except that this doesn't work!):

type testType
Field lots.otherType(10)
end type


GitTech(Posted 2003) [#7]
Type testType 
Field lots.otherType[10]
End Type 


Just use [] instead of (). But remember, only one-dimensional arrays are allowed!!


soja(Posted 2003) [#8]
<EDIT: beat to the punch...>
Yes, but you can't put normal arrays in custom types. You must use what are sometimes termed as "BlitzArrays" (search in the forum for descriptions of differences... the main annoying ones are that they can only be one dimension, and they don't show up well in the debugger).

Like this:

type testType
Field lots.otherType[10]
end type

(notice the difference in brackets versus parens... also, you don't use "Dim")


EricZann(Posted 2003) [#9]
Good enough for what I want though. Thanks!