Hi All,
I've got a problem I can't work out.
I have created some nested types, and declared a variable of the final type.
I realised I had forgotten to initialise that variable when I got an NPE when I first tried to assign a value to one of the items in the variable.
I checked the forums and found Erel's example of using types to create a linked list (http://www.b4x.com/forum/basic4andr...linked-list-using-type-keyword.html#post39085), where he shows the initialize.
But, I have used arrays nested in the types, which seems to be stopping the initialize from working, as I still get an NPE when I assign a value.
I have copied the key code from my program. Can anyone tell me what needs to be done? Do I need to initialize the lower level items somehow?
The line with the assignment of 1 to the UnitX gives an NPE.
I can't just do Player.Initialize as that gives a syntax error.
What am I doing wrong? Or can't I create types like this with the arrays embedded? Or is my usage of the UnitX item wrong?
I tried removing the array from the Player DIM and using the Player.Initialize but it still gives an NPE on the modified (no index on the Player) assignment.
Thanks,
PH
I've got a problem I can't work out.
I have created some nested types, and declared a variable of the final type.
I realised I had forgotten to initialise that variable when I got an NPE when I first tried to assign a value to one of the items in the variable.
I checked the forums and found Erel's example of using types to create a linked list (http://www.b4x.com/forum/basic4andr...linked-list-using-type-keyword.html#post39085), where he shows the initialize.
But, I have used arrays nested in the types, which seems to be stopping the initialize from working, as I still get an NPE when I assign a value.
I have copied the key code from my program. Can anyone tell me what needs to be done? Do I need to initialize the lower level items somehow?
B4X:
Sub Process_Globals
Type SingleUnit (UnitX As Int, UnitY As Int, UnitAlive As Boolean, UnitImage As ImageView)
Type Squad (Unit(4) As SingleUnit)
Type Army (Tank(2) As Squad, Cavalry(2) As Squad, Infantry(2) As Squad, Artillery As Squad, General As SingleUnit)
End Sub
Sub Globals
Dim Player(2) As Army
End Sub
Sub Activity_Create(FirstTime As Boolean)
Player(0).Initialize
Player(1).Initialize
Player(0).Tank(0).Unit(0).UnitX = 1
End Sub
The line with the assignment of 1 to the UnitX gives an NPE.
I can't just do Player.Initialize as that gives a syntax error.
What am I doing wrong? Or can't I create types like this with the arrays embedded? Or is my usage of the UnitX item wrong?
I tried removing the array from the Player DIM and using the Player.Initialize but it still gives an NPE on the modified (no index on the Player) assignment.
Thanks,
PH