Types within Type

BlitzPlus Forums/BlitzPlus Tutorials/Types within Type

superStruct(Posted 2010) [#1]
How to create a hierarchy of types in BlitzPlus


superStruct(Posted 2010) [#2]
I was really stuck on this problem one night. Finally, I was just screwing around when I got lucky and struck proverbial gold. I was writing a program to keep track of grades and I needed to create assessments in classes. Here's how I did it.




Stamm(Posted 2010) [#3]
That one could be very useful by making possible a better aorganisation within Type


deload(Posted 2015) [#4]
I tried this:

Type Vector3D
	Field x#=0.0
	Field y#=0.0
	Field z#=0.0
End Type

Type Player
	Field uType = 0
	Field uState = 0
	Field uPosition.Vector3D
	Field uV.Vector3D
	Field uA.Vector3D
	Field uF.Vector3D
	Field uJump = 0
	Field uFall = 0
	Field uAction1 = 0
	Field uAction2 = 0
	Field uAction3 = 0
End Type

Function MainLoop()
	SetBuffer BackBuffer()
	Repeat
		Cls
		MovePlayer()
		If KeyHit(1)
			End
		EndIf
		DrawImage player,vPlayer\uPosition\x,vPlayer\uPosition\x
		Flip
	Forever
End Function

Function MovePlayer()
	If JoyY(0) = "-1.52588e-005"
		jSigY = 0
	Else
		jSigY = JoyY(0)
	End If
	
	If (vPlayer\uPosition\x + (jSigX * joyFactor)) < 0
		vPlayer\uPosition\x=1
	Else If (vPlayer\uPosition\x + (jSigX * joyFactor))+ImageWidth(player) >= GraphicsWidth()
		vPlayer\uPosition\x = GraphicsWidth()-ImageWidth(player)
	Else
		vPlayer\uPosition\x = vPlayer\uPosition\x + (jSigX * joyFactor)
	End If
	
	If velocityY < velocityMax
		velocityY = velocityY + acceleration
	End If
	
	If jSigY<0 And (velocityY > -velocityMax)
		velocityY = (-velocityY)
	End If 
	
	If (vPlayer\uPosition\y + (velocityY)) < 0
		vPlayer\uPosition\y = 1
	Else If (vPlayer\uPosition\y + (velocityY))+ImageHeight(player) >= GraphicsHeight()
		vPlayer\uPosition\y = GraphicsHeight()-ImageHeight(player)
	Else
		vPlayer\uPosition\y = vPlayer\uPosition\y + velocityY
	End If
End Function


No syntax errors but the code instantly crashes at runtime on Win7.
Maybe thatīs already enough to meet the limits of "You better donīt use types with large numbers of objects".


deload(Posted 2015) [#5]
Self correction:
You have to initialize the types within a type correctly. It was not sufficient to create a "new Player" but you also have to initialize the field values inside the type if they are custom types themselves.
After modifying the following code my little game ran flawlessly:

Global vPlayer.Player = New Player
vPlayer\uPosition = New Vector3D
vPlayer\uV = New Vector3D
vPlayer\uA = New Vector3D
vPlayer\uF = New Vector3D