Could we make a Nesting Type
Could someone give some simple example on that
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.
Thanks NTense. Its help a lot
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.
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.)
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
Type testType
Field lots.otherType[10]
End Type
Just use [] instead of (). But remember, only one-dimensional arrays are allowed!!
<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")
Good enough for what I want though. Thanks!