Site hosted by Angelfire.com: Build your free website today!

gameBlender and Python...

Okay, so what exactly is this python stuff anyway? And how the heck do I use it...

Python is a run-time interpreted language which, in my opinion, is quite similar to Java. I guess Python beat them to the punch...Its a programming script in a manner of speaking.  You can have variables, expressions, etc. However, there is one key point: Most "variables" in python are actually "objects". You must understand objects then ! :) So I will try to explain here:

OK I'll start off by telling you that you already know what objects are. That's right. Look up from your computer screen over to your wall and find the light switch. That's an object, right? Of course. Now, what does that light switch do? I mean, what are its actions, its "verbs". Yes, it TURNS ON and TURNS OFF. These could also be called its methods . With an object in programming, its functions and procedures are called its methods, because you can call these to make the object do something. Just like you "TURN ON" the light switch to turn complete its circuit.  Now, what does the light switch look like? Is it brown, or white, or black? Its color could be called a propertyof the switch. Of course that makes perfect sense! Now each object can have its own properties and methods. So you could have a brown light switch and a white light switch too, and each one knows how to act on its own. It is self-contained. That is the purpose of having objects. Another word used isencapsulation . I know, I hate these stupid big words too. Seems like some people just like to come up with words rather than ideas!  So, to summarize, here is our light switch:

methods:
TurnOn
TurnOff

properties:
Color

So if you were to implement a light switch in code, you would have an object that had two functions TurnOn and TurnOff. Of course, you can also pass parameters into these functions if you wish. You will also have a property called color. This is nothing more than a stored variable the object owns. How do you get to your properties and methods in code? Well,  almost every object oriented language uses the dot "." operator to do this.  So, to call the function (method) TurnOn of the light switch, you would say  VarLightSwitch.TurnOn  .  Now, wait a minute - where did I get my light switch object anyway? Well, you made a variable and said it was going to be of type LightSwitch. LightSwitch was an object class either you wrote earlier or someone else wrote for you. This class has the methods and the properties that you want a LightSwitch "object" to have. Now, just as you can declare a variable of type integer, or type string, now you can declare a variable of type LightSwitch. And because LightSwitch is a "object class" the new variable you just made is now an actual object. Remember, just as you cannot assign the like this:  5 = int,  or int =5 , (no kidding, int is a TYPE not a variable). You cannot say  LightSwitch.TurnOn, or LightSwitch.Color = blue because LightSwitch isn't a variable, its a data type. You can make a variable called VarLightSwitch of type LightSwitch  and now you can call the methods and properties because now your object actually does exist in computer memory. Anyway, enough about basic object classes. - remember, this is general object oriented stuff, it is not just Python dependent. Languages such as C++ and VB5.0 and up also use objects. Now let's check out one more really cool thing about objects inheritance. You really should know this, OK? It helps for use in gameBlender ! Please keep reading.

SO now you have your LightSwitch class and you want to do something more powerful with it. You want to make a light that slowly dims out when it is turned off.  Great, you think, now I have to rewrite an entirely new class to do the job. NO YOU DON'T ! :) This is the great thing about OOP. All you need to do is "inherit" the functions from the basic LightSwitch class, and change the TurnOff function to meet your needs. The nice thing about this is that now you didn't have to write the code for the TurnOn function again at all, your new object inherited it, as well as the color property. But now you have a nice fancy light switch, perhaps you called it DimmerSwitch. It is handy to know about inheritance, because in gameBlender, most objects have parent classes. So remember, unless the programmer has declared some functions as private, all the parents' methods and properties will be passes unto the child. OK? So if you don't see the function you thought you should have in the gameBlender class, check its Parent and see if it's there. If the parent has it, you will have it too. (For now in gameBlender, this is true)

whew. you made it. Now time to see how to apply this object stuff in gameBlender! Continue.