1

I'm just starting out with the PyMunk physics library. I'm having trouble using apply_impulse(). I'm calling it like this:

player.body.apply_impulse(player.body, (10,10), (10,10) )

However, I'm getting this error:

TypeError: apply_impulse() takes at most 3 arguments (4 given)

Why is this and what's the correct way to call apply_impulse()?

Elliot Bonneville
  • 51,872
  • 23
  • 96
  • 123
  • not that i know anything about pymunk, but why are you passing player.body to a function within player.body? and furthermore, maybe player.body itself is two arguments? – machine yearning Jun 18 '11 at 00:57
  • Because the first variable of apply_impulse is a reference to self. No, player.body is one variable, it's the 'rigidbody' of player. That is, the class that contains the physics functions for the object. – Elliot Bonneville Jun 18 '11 at 01:03
  • This is strange. I've used PyMunk before, and the code looked OK so I looked up the [documentation](http://pymunk.googlecode.com/svn/tags/pymunk-1.0.0/docs/api/index.html) which shows that you are indeed doing the right stuff. Possibly the documentation is outdated? Could you post the actual function, "apply_impulse()" from the library you are currently using? – Jeff Gortmaker Jun 18 '11 at 01:05
  • 1
    The first argument is "self", which you need not specify explicitly. "self" is always the first parameter within methods to that particular class. Try removing player.body. – Pavan Yalamanchili Jun 18 '11 at 01:05
  • but when you call a function on an object you don't need to pass the object itself. `self` is in the function definition but you don't need to pass it when you call the function – machine yearning Jun 18 '11 at 01:06

1 Answers1

2

When you call a member function on its object you usually don't need to pass the object itself as the first parameter. self is in the function definition of every member function but not in the function call.

see this post: What is the purpose of self?

Community
  • 1
  • 1
machine yearning
  • 9,889
  • 5
  • 38
  • 51
  • That was it, thanks. Silly me. You know what though, as a Python beginning programmer, the documentation was a little confusing on that. I mean, it's saying 'Call function x with params y and z' when you actually need to call function x with param z alone. That gets confusing. /rant Anyways, thanks for straightening it out for me. :) – Elliot Bonneville Jun 18 '11 at 01:14
  • NP I agree that from a syntactic viewpoint it doesn't make much sense. However it is there to deal with some other ambiguity issues that you'll probably discover when you become more familiar with object-oriented programming, at which point you're likely to appreciate the clarity granted by this approach. :) – machine yearning Jun 18 '11 at 01:17