[Solved]About Splitting the Code

I tried to seperate some functions to a seperate file, but it never worked… :frowning:

My intension is while pressing the “r” key, the model’s position will be reset to the initial place.

## arFunc.py
# _targetObj_ and _pos_ are parameters
def resetPosition(self, _targetObj_, _pos_):
## main.py
import arFunc

class World(DirectObject):
    def __init__(self)
        self.growl = Actor.Actor(MYDIR+"/models/growl")
        growlStartPos = self.environ.find("**/start_point").getPos()
        self.growl.setPos(growlStartPos) #The main purpose I want to do#

        self.accept("r", arFunc.resetPosition(self.growl, growlStartPos) )

When I run the script (main.py), it would complain about:

AssertionError: method not callable in accept (ignoring): None []

Any ideas?

is it correct that you used


in the file but called for

ac<->ar ?
never mind if that’s how it’s supposed to be. i’m still pretty new to python

Thanks for pointing it out~

That’s a mis-typing error, so I still need help to solve this problem…

I am also very new to Python :smiley:

Parameters that you want to be included in the target method must be added as a third (list) parameter to “accept”.

def accept(self, event, method, extraArgs=[])

so you need to change
self.accept(“r”, arFunc.resetPosition(self.growl, growlStartPos) )
self.accept(“r”, arFunc.resetPosition,[self.growl,growlStartPos])

Thanks so much!