Type Field initializers

Blitz3D Forums/Blitz3D Programming/Type Field initializers

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.

On the other hand
John pickfords solution ( I personally prefere the Handle / Object Variant ) gives you additional Options.
You could for instance pre-initialize your complete weaponset or fleet of spaceships.
Type TypeWeapon
	Field WeaponID%
	Field Ammo%
	Field FireRate%
	Field Velocity%
	Field Range%
	Field Damage%
	Field Force%
	Field Weight%
End Type
For i=1 To 2
	x.TypeWeapon=Object.TypeWeapon(CreateTypeWeapon(i))
	Print x\WeaponID
	Print x\Ammo
Next
WaitKey()
End

Function CreateTypeWeapon(Flag=0)
	tw.TypeWeapon = New TypeWeapon
	If Flag=1
		tw\WeaponID% = 1
		tw\Ammo% = 500
		tw\FireRate% = 2
		tw\Velocity% = 100
		tw\Range% = 500
		tw\Damage% = 1
		tw\Force% = 1
		tw\Weight% = 50
	ElseIf Flag=2
		tw\WeaponID% = 2
		tw\Ammo% = 2000
		tw\FireRate% = 30
		tw\Velocity% = 1000
		tw\Range% = 20000
		tw\Damage% = 4
		tw\Force% = 5
		tw\Weight% = 250
	EndIf
	Return Handle(tw)
End Function