Spright Active Member May 10, 2023 #1 I am adding datatype point (i know vector2d exist, this is actually an excericse in OO in B4a). so i would normally think about it like this B4X: Copy Class Point Dim mX As Float Dim mY As Float Sub New(x As Float,y As Float) mX = x mY = y End Sub End Class So i added a class module, adn filled it in, I noticed there was a place for vars, so i moved them there.Of course it's still wrong, but I'm lacking examples hw to do ir correctly? B4X: Copy Sub Class_Globals Private mX As Float Private mY As Float End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize End Sub Class Point Sub New(x As Float,y As Float) mX = x mY = y End Sub End Class
I am adding datatype point (i know vector2d exist, this is actually an excericse in OO in B4a). so i would normally think about it like this B4X: Copy Class Point Dim mX As Float Dim mY As Float Sub New(x As Float,y As Float) mX = x mY = y End Sub End Class So i added a class module, adn filled it in, I noticed there was a place for vars, so i moved them there.Of course it's still wrong, but I'm lacking examples hw to do ir correctly? B4X: Copy Sub Class_Globals Private mX As Float Private mY As Float End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize End Sub Class Point Sub New(x As Float,y As Float) mX = x mY = y End Sub End Class
Erel B4X founder Staff member Licensed User Longtime User May 10, 2023 #2 Code: Copy Sub Class_Globals Private mX As Float Private mY As Float End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize (x As Float,y As Float) mX = x mY = y End Sub Upvote 0
Code: Copy Sub Class_Globals Private mX As Float Private mY As Float End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize (x As Float,y As Float) mX = x mY = y End Sub
aeric Expert Licensed User Longtime User May 10, 2023 #3 I thought using Type also will do. B4X: Copy Type Point(mX As Float, mY As Float) Last edited: May 10, 2023 Upvote 0
Spright Active Member May 12, 2023 #5 How do you actually use these examples? I could not find how to create new objects If you want the class above to output an object like so: B4X: Copy Sub clone : Point() Return New Point(mx,my) EndSub Upvote 0
How do you actually use these examples? I could not find how to create new objects If you want the class above to output an object like so: B4X: Copy Sub clone : Point() Return New Point(mx,my) EndSub