Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Functions and Vec2d help
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
7Ate9




PostPosted: Mon Dec 27, 2010 11:02 pm   Post subject: Functions and Vec2d help

K so i am a starter in python and i have a couple questions.
q1- def update(self,event)
I was wondering What that self is for, and what it represents, what the event also stores/represents.
q2- How do you call upon other function when needed, maybe call upon a mouse event function when drawing something?

q3 - What is Ved2d, and how can i get it or use it?

It would greatly appreciate if i could get an answer and and example with it to make things easier.
Sponsor
Sponsor
Sponsor
sponsor
7Ate9




PostPosted: Mon Dec 27, 2010 11:27 pm   Post subject: RE:Functions and Vec2d help

Also I would like to know what Tkinter is and how to use it, thanks in advance.
DtY




PostPosted: Tue Dec 28, 2010 1:13 am   Post subject: RE:Functions and Vec2d help

You are using Pygame, I assume? (Pygame is not part of the standard python distribution)

q1
There is no way I can give a very useful answer to this without having some more context.

That said, self is just a variable name, but it is commonly used in object methods.

You have probably not come across objects properly yet. In python, all variables are objects, and objects have their own functions (called methods) that do stuff to the instance of the object.

For example, you have a string named s:
Python:
s = "hello"

String objects have the method upper(), which will return the string in upper case.
Python:
s.upper()

s.upper() is actually just syntactic sugar in Python (syntactic sugar a feature of a language that is only there for convenience, does not add anything that couldn't otherwise be achieved).
Python:
str.upper(s)

Is exactly the same thing. str is the class that s belongs to.

If this method were defined in Python somewhere, it would look something like this:
Python:
class str:
    def upper(self):
        #Do the transformation

The first line is used to create the class of object, and then you add the method upper() to it. When you call it in the object form, that is s.upper(), s is passed as the first argument. This argument is conventionally called self, but it can be called anything.

If you have not created your own classes before (it's very doubtful you have yet), this wont mean much to you. What you need to know is that when you see self as the first argument, it means that it belongs to a class.

You didn't provide enough information for me to know what type that method is for, but say you have a variable m that is of that type. You would then call that method m.update(event), rather than update(m, event). The "self" argument goes before the dot. I also don't know what event is, because I don't know where you pulled that from.

q2
You use the function notation, a reference to the function (the name of it), and then the arguments between parentheses. If there are no arguments to it, you would use a set of empty parentheses.

q3
Where have you come across Vec2d? It is not part of python nor pygame. I can only assume that it is a class that implements a two dimensional vector.

tkinter
TKinter is a python widgets library. Widgets are graphical buttons, sliders and that stuff (so unlike pygame where you draw shapes and images and then process events for mouse moving buttons and stuff; you would create buttons and the like, and get events when they're clicked on and the like). As for using it, I can't help you there, google around.

By the way, you wont be able to mix pygame and TKinter in the same window.
7Ate9




PostPosted: Wed Dec 29, 2010 6:00 pm   Post subject: Re: Functions and Vec2d help

Thank you, i understand functions much better now.
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: