Issues calling methods

I am trying to get the functionality of my game down before the prettiness. I figure learning to share game data over WiFi is easier to expand on than to jump into after that whole system is in place. My issue is that my script doesn’t work. I have found that importing the script as if it were a library from the Python shell not only allows it to run, but allows me to see the error messages. I am seeing the error in the following image file.


the ezimp tool is a handwritten tool which allows me to import from a source outside my Visual Studio’s python installation. It does nothing but sys.path.insert(‘pathtolibraries’).

What can I do to solve this error?

I’m not familiar with the online functionality, but I’m guessing that the “accept” mentioned there is just Panda’s standard DirectObject/ShowBase “accept” method.

In that case, the second parameter is intended to be a reference to the method that you intend to have Panda call when the event fires. However, what you seem to be doing above is actually calling the method, and thus passing its return-value into the call to “accept”, rather than the method itself.

To get a reference to a method, you simply use its name, without brackets or parameters.

Of course, this means that you don’t get to pass in your parameters. In the case of a method being passed into “accept”, you should be able to provide them in the optional “extraArgs” parameter, stored in a list.

Your call might thus look something like this:

self.accept('space', self.launchOnline, extraArgs = [80, 'host'])

Note the lack of brackets or parameters for “self.launchOnline”, and the parameters then being provided via the “extraArgs”.

And like magic, it works!
Thank you! I presume that tasks cannot return anything other than Task.cont and similar. I would need to have a global variable for that and just have that task edit it as self.variable.

I’m glad, and it’s my pleasure. :slight_smile:

I believe so, yes. (Or at least, returning something else may cause them to not work properly, I think.)

Granted that I don’t know what you’re doing, that seems like it should work. (Although it wouldn’t be a global variable, as such, since “self.” implies that it’s attached to an instance of a class. But that’s a matter of clarifying terminology; the idea should work.)