Type Dependencies

BlitzMax Forums/BlitzMax Beginners Area/Type Dependencies

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I think I had a similar issue to this - but it may just be my dodgy coding (actually this is the most likely :) )

I have a user defined type and one of its fields is another user defined type. The types are in different files and all files are Includes in the main game file. Probably easier to see in the code. Here is the first type and in SHIP.BMX:

'Enemy Ship - extends TypShip.  This is abstract so cannot be created itself.
Type typEnemyShip Extends TypShip abstract
	Field tAttackPattern:typAttackPattern
	Field varSplineTime:Float = 0.0
	Field intCurrentSpline:Int = 0
	Field intKillPoints:Int
EndType


'Enemy Spinner - extends TypEnemyShip
Type TypEnemySpinner Extends typEnemyShip
...
... some methods
...
endtype

The enemy spinner has a field of type typAttackPattern. The attack pattern type is in a seperate file ATTACKPATTERN.BMX thus:

Type typAttackPattern

	Field intEnemyCount:Int
	Field intAttackSpeed:Int
	Field tMotionPath:typMotionPath[5]

EndType

Global tSpinnerPattern1:typAttackPattern = New typAttackPattern
tSpinnerPattern1.intAttackSpeed = 100
tSpinnerPattern1.intEnemyCount = 1

For Local i:Int = 0 To 4
	tSpinnerPattern1.tMotionPath[i] = arrSpinnerPath1[i]
Next


In the first file SHIP.BMX 10 enemy spinners are initialised thus:

Global arrEnemySpinner:TypEnemySpinner[10] 'create 10 enemy spinners

For Local i:Int = 0 To 9
	arrEnemySpinner[i] = New TypEnemySpinner
	arrEnemySpinner[i].Initialise()
	arrEnemySpinner[i].tAttackPattern = tSpinnerPattern1
Next

but this fails in the compiler on the line:
arrEnemySpinner[i].tAttackPattern = tSpinnerPattern1

However if I move initialisation of the 10 spinners to the ATTACKPATTERN.BMX file then everything is fine - but it has to be after the line:

Global tSpinnerPattern1:typAttackPattern = New typAttackPattern

I guess it makes sense that you can't assign the SpinnerPattern1 as it has yet to be initialise - so I guess maybe the order that files are included is relevant. It's just that in the past this has never seemed to be a problem - everything just seems to get resolved be the compiler provided I use includes for all the files.

Anyway it's not really a problem - I just moved my declarations out to a seperate file together an everything is hunky dory, just thought it might be relevant.