-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|633|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Blogs Home -> Blogs


 
power mousey
Created : 03 March 2008
 

Learning OOP Ropes



Yes, I'm learning the ropes of OOP programming and in BlitzMax.

Here are 2 very short examples...as I get down the concepts and techniques.





and the second example


 

Comments


Monday, 03 March 2008, 16:25
Nolan
A method is a function acting on an already created object, so you don't have to use Self. Think of a type function in BlitzMax as a Static function in C++.

Example:


Also, it's a bad idea to pass a string into the type and then load the image. If you end up creating, for instance, 50 Kats using the same image, you'll have loaded that image 50 times, wasting precious memory. A better idea would be able to pass an already loaded TImage into the function.
Monday, 03 March 2008, 21:50
power mousey
hmmmmmmm....I see what you mean.

and yeah, you're right it would be a bad idea to create
the same image with creating more but different objects.
Passing an already loaded image into an object would be ideal and good.

Thank you, Nolan.

Here is a modified and improved version of sorts.




I'm following the yellow brick road more.
To the Wonderful World of OOP.
Tuesday, 04 March 2008, 07:43
Phoenix
Think of a type function in BlitzMax as a Static function in C++.


Actually, to be picky, a static C++ function wouldn't be able to access the "name" member since it's not static and requires an instance to be used.

Good luck with the OOP, mousey!
Tuesday, 04 March 2008, 08:35
Nolan
Actually, to be picky, a static C++ function wouldn't be able to access the "name" member since it's not static and requires an instance to be used.


That's what I was saying. A Function in a Type, in Blitzmax, cannot access Fields. A Method, which would be a non-static C++ function inside of a class, can. Sorry for any confusion... the use of the word "function" can be read many different ways.
Tuesday, 04 March 2008, 09:40
JL235
It can also be described as a static or class method and in some object-oriented languages a static method is acting on an instance; it's acting on the instance of the class.
Tuesday, 04 March 2008, 10:19
Phoenix
Sorry for any confusion... the use of the word "function" can be read many different ways.


I misunderstood you then
Tuesday, 04 March 2008, 12:05
power mousey
thank you Phoenix.

and thank you all guys for the the information.
Seriously. I was getting around and wondering why and whats the difference between methods and functions.
And then it hit me like a ton of bricks last night.
Methods are like functions but are class members for the individual objects...the ones you create from the blueprint.
Whie a function which is in the blueprint you can access thru the blueprint to do whatever its thing is...but provided that you declared an object first.

I think you guys know but here is an example
and modified again.




I'll be doing some more examples and more coding from where I'm currently at. Before I press on towards arays and lists of objects, inheritance and polymorphism.
I'll just keep it simple with one object for now.
By the way, I have 18 days left with the demo version of BlitzMax.
Thursday, 06 March 2008, 15:47
power mousey
I'm slowly learning more about OOP.
I learned how to create, define and assign a type pointer
to a object cat of type KAT.

But mostly I learned how and by reading um the docs in BlitzMax and thru a few hours of trial and error, how to create an array of objects.
Well not exactly. That is, how to set up an array of blueprints grouped and referenced to what will be the array.
And then index the second element and create an object from the blueprint....of type KAT.

Here is the program.




thats it for today.
I'm all BlitzMaxed out.

ahhhhhh yeahhhh!, the demo version doesn't allow you to use the command Delete. The docs said it would be reserved for use in another version.
Thursday, 06 March 2008, 18:39
Nolan
How about a challenge to help you learn? Try adding a Draw() method to the Type Kat, so instead of typing "Drawimage...." for each Kat, you can just call instance.draw(). Just a suggestion, of course.

Also, the Delete keyword isn't used in the full version either, as of now. Mark just set it aside in case he wants to use it in the future.
Friday, 07 March 2008, 04:26
power mousey
okay, you're on Nolan.
And I'm up for the challenge too.
I'll start designing a program tomorrow in the afternoon.
By the way...the comments in the program and my previous post are wrong concerning 4 memory blueprints grouped for the array. Actually its 3. [3]--> array index of 0,1, and 2.

and thanks for that information about Delete. Was just wondering if Mark included it or did anything with it for the latest, updated version of BlitzMax.
Friday, 07 March 2008, 16:41
power mousey
well Nolan and everbody else too...

here is a program that makes use of both a Draw method of an object and also a Draw Function within the blueprint of KAT itself.



I also make use of an object pointer...of type KAT.
And use it to get the base address of first object created and also derefence it to get the address of the third object and use it in place of the object variable that its associated with.
Saturday, 08 March 2008, 10:23
Nolan
Nice job, Mousey... although it might be more useful to pass x,y into the Draw() method, so that your Kats won't draw on top of each other every time.

Are you enjoying BlitzMax?
Saturday, 08 March 2008, 12:38
power mousey
True, I could've passed parameters into both the Method and the Function. I will eventually.
Now, I have to learn about inheritance, extends and extension, and about Morph Island and the Poly Natives and their mysterious powers of polymorphism.

Yes, I'm enjoying BlitzMax and also made some game functions too. But I'm in a quandry of sorts. I have 14 days left for the trial version of BlitzMax. So, I better get on the ball or start raising the pace into learning and using BlitzMax.
And especailly cause Nuclear Basic is coming out sometime this month of March. I already pre paid for it. So, I'm wondering if I should get BlitzMax and/or settle in for Nuclear Basic.
My budget is limited and already allocated for the next few months.
Perhaps DD(JL) is right.... I should go back with C/C++
and/or Python. Anyway, I hear that BlitzMax...the full retail version has minb3d for 3d graphics and models.
I really want and like to get back into 3d graphics and 3d models.

Wait! Ya hear that!?? I think I heard my Geisha Girl calling for me. My Wolfie howling for me. Xeon the Alien doing his 3d Alien Aerobics, and the Chaldean Cat meowing and walking thru Babylon too.
And what the!?? My three Power Ninjas doing their Ninja stances and moves to the Power Ranger theme song. I got a kick out of that.