As you know, I can't test right now. But maybe, with the DIM statement the array is already defined and assigned.
What error do you get?
I can't figure out how to assign a class to an array of that class type.
Error Given:ArrayOfClassError.jpg
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
Last edited by kryton9; 10-05-2017 at 07:49.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
As you know, I can't test right now. But maybe, with the DIM statement the array is already defined and assigned.
What error do you get?
Here is a screenshot of the error. Actually I will add it to the first post to keep it together. Thanks Mike.
http://www.thinbasic.com/community/s...ll=1#post93523
Last edited by kryton9; 10-05-2017 at 07:50.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Are Private and Public valid keywords? The editor doesn't highlight them.
Hi,
thinBasic OOP is quite at the beginning and not all is really correct as it should be, so you must be patient and maybe we will go together into the right direction.
Especially arrays of UDTs is an area not really covered.
Anyway, here some hints
Public, Private are keywords just parsed but internally they just do nothing. They only mark UDT elements with an internal flag public/private for future usage.
When "Dim particles ( numPoints ) As cParticle" is encountered, the cParticle._Create contructor is automatically called.
If you expect constructor is executed when you invoke the NEW keywork, at the moment it is not for arrays of UDT. But this can be changed.
So, at the moment, better to have contructor and destructor only as GLOBAL function to the UDT and add some specialized function.
To test how many optional parameters has been passed, there is Function_CParams function.
You code can be changed into something like that to get what I said. Hope this can help.
Uses "Console" 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 Init ( Optional x As Single, Optional y As Single, Optional z As Single ) Static conta As Long Incr conta PrintL $TAB, Function_Name, conta Me.vec2 = FALSE If Function_CParams = 0 Then'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 SetParticle ( ) Static conta As Long Incr conta PrintL Function_Name, conta '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 Me.pos.Init( Rnd ( width ), Rnd ( height ) ) Me.prevPos.cpyFrm(Me.pos) Me.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 Particles(i).SetParticle() PrintL i, particles(i).pos.x Next PrintL "Press a key to end program" WaitKey
Last edited by ErosOlmi; 10-05-2017 at 11:44.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Helps a lot, thank you very much Eros
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Bookmarks