I know i can use the accept function to react to a mouse event
with the following line of code:
self.accept("mouse1", player.getRayCollision)
but what can i do to start a method with more arguments?
The following won´t work:
self.accept("mouse1", player.getRayCollision(var1, var2, var3))
wezu
February 22, 2012, 5:40pm
2
Try:
self.accept("mouse1", player.getRayCollision, [var1, var2, var3])
Even if you have just one extra argument you need to pass it as a list.
drwr
February 22, 2012, 5:41pm
3
self.accept("mouse1", player.getRayCollision, extraArgs = [var1, var, var2])
You can also use Python’s built-in lambda syntax:
self.accept("mouse1", lambda: player.getRayCollision(var1, var2, var2))
but most beginners to Python find the first syntax easier to understand.
David
Thanks for the fast answers.
Are there any major differences between these two approaches?
I read in this topic that lambda creates a unnamed and unowned function. Is this just something that is important on the hardware side or is there actually a difference in the program?
drwr
April 24, 2012, 4:48pm
5
There is not a major difference in the program execution either way. It’s just a question of which syntax makes more sense to you.
David