kryton9
10-05-2017, 05:26
I can't figure out how to assign a class to an array of that class type.
Error Given:9691
Here is sample code to see what I mean. Thanks
Uses "Console"
Type cVec
Public
x As Single
y As Single
z As Single
Private
vec2 As Boolean ' is this a Vec2 or Vec3, default vec2 is false, auto set when created
Public
Function _Create ( Optional x As Single, Optional y As Single, Optional z As Single )
Me.vec2 = FALSE
If x = "" Then
Me.x = 0
Me.y = 0
Me.z = 0
Return
End If
Me.x = x
Me.y = y
If z = "" Then
z = 0
Me.vec2 = TRUE
End If
Me.z = z
End Function
Function cpyFrm ( copyFromVec As cVec )
Me.x = copyFromVec.x
Me.y = copyFromVec.y
Me.z = copyFromVec.z
End Function
End Type
Type cParticle
pos As cVec
vel As cVec
acc As cVec
prevPos As cVec
maxSpeed As Single
Function _Create ( )
Dim pos As cVec( Rnd ( width ), Rnd ( height ) )
Dim vel As cVec 0, 0
Dim acc As cVec 0, 0
Dim prevPos As cVec 0, 0
prevPos.cpyFrm pos
Single maxSpeed = 1
End Function
End Type
Int32 width = 640
Int32 height = 480
Int32 numPoints = 10
Dim particles ( numPoints ) As cParticle
Local i As Int32
For i = 1 To numPoints
particles( i ) = New cParticle '<<<<< how should I do this, getting an error, thanks
'particles( i ) = New cParticle() '<<<<< how should I do this, getting an error, thanks
Next
PrintL "Press a key to end program"
WaitKey
Error Given:9691
Here is sample code to see what I mean. Thanks
Uses "Console"
Type cVec
Public
x As Single
y As Single
z As Single
Private
vec2 As Boolean ' is this a Vec2 or Vec3, default vec2 is false, auto set when created
Public
Function _Create ( Optional x As Single, Optional y As Single, Optional z As Single )
Me.vec2 = FALSE
If x = "" Then
Me.x = 0
Me.y = 0
Me.z = 0
Return
End If
Me.x = x
Me.y = y
If z = "" Then
z = 0
Me.vec2 = TRUE
End If
Me.z = z
End Function
Function cpyFrm ( copyFromVec As cVec )
Me.x = copyFromVec.x
Me.y = copyFromVec.y
Me.z = copyFromVec.z
End Function
End Type
Type cParticle
pos As cVec
vel As cVec
acc As cVec
prevPos As cVec
maxSpeed As Single
Function _Create ( )
Dim pos As cVec( Rnd ( width ), Rnd ( height ) )
Dim vel As cVec 0, 0
Dim acc As cVec 0, 0
Dim prevPos As cVec 0, 0
prevPos.cpyFrm pos
Single maxSpeed = 1
End Function
End Type
Int32 width = 640
Int32 height = 480
Int32 numPoints = 10
Dim particles ( numPoints ) As cParticle
Local i As Int32
For i = 1 To numPoints
particles( i ) = New cParticle '<<<<< how should I do this, getting an error, thanks
'particles( i ) = New cParticle() '<<<<< how should I do this, getting an error, thanks
Next
PrintL "Press a key to end program"
WaitKey