AGK has a lot of difficulty with subscripts and arrays of user defined types.
I had to make it a practice to use a variable in the 0 element to store my array sizes. Like so:
type myType
aSize as integer
someVar as integer
endtype
dim myArray[100] as myType
myArray[0].aSize = 100
Then do this any time you resize the array and use that array element in loops and such so you are within the array subscript bounds.
If you have mistakes that carry you out of bounds on your UDT arrays it is very common that AppGameKit will not catch them and continue running in without error in windows. On iOS and Android it will crash with no error message. Which makes it horrible to trace and makes it doubly important to keep track of the array bounds on your own.
That said, how are you getting AppGameKit to define a type in an if statement? I had no idea it was possible and I don't think it is good practice. Type, global, constant declarations should all be at the top of your program and the first thing you do! I also make it a habit to initialize all of the arrays I need at the beginning of my program and set their size counter to 0 so that I can easily call them later without being concerned that the have yet to be declared. Saves a ton of work because I can have arrays for set of sprite objects and I can say something like this:
for i = 1 to myArray[0].aSize
if GetSpriteExists(myArray[i].spriteID) = 1
inc count
endif
next i
if count = myArray[0].aSize
// the object was already created!
else
// the object needs to be initialized and created, but we should ensure that it is cleaned up first!
endif
This provides a bit of an out for mistakes, say you accidentally deleted one of the sprites in the object, but just hid all of the others. This type of method will clean up and reinitialize everything so you're back in working order. Also it should be noted that AppGameKit has a very small possibility of accessing non-null memory when using UDT arrays. This means every once and a while in a large program you will get some junk values in your arrays. So when you initialize your array with dim or resize it you should make it a practice to set all of the type elements to zeroes or nulls (the ones which don't contain data). This will save you from mysterious behavior later down the road, trust me!
I do really wish AppGameKit could pass arrays by reference to functions. This would allow us to have a bunch of really awesome error checking methods and array functions like sorting, inserting, removing duplicates, checking out of bounds, etc. Instead we have to write them for each and every different array