Executing imported module problem




File "/home/user/BGMC_Projects/BGMC17_GoldenReelFishing/Blends/Lake.blend/Choices.py", line 31, in baitChoice
TypeError: load() missing 1 required positional argument: 'self'
Blender Game Engine Finished

Could someone explain me why I get this?

happened to me as well, try using ‘loader’ or ‘load_bait’. If you use just ‘load’ for the module name it will break.

EDIT, have you added cont within the function brackets (function(cont) )?

Doesn’t fix:(

Though I’ve seen that error many times I can’t be sure if this is your case, try


import myModule
 
getClass = myModule.myClass() # the bracket is where the "self" is being instanced... I think
getFunction =  getClass.myFunction


It tells you, that you forgot to met the convention of an object method -> provide an argument that receives a reference to the current object. Many Programming languages provide an implicit but hard-coded variable (Java; C++: this). In Python you can call it as you like. Typically it is called “self”.

Just add it to your method declaration and it will be fine:


class ...:
   def load(self): # <- never forget the reference to the object as first argument
      ...

OK! I found a fix ago, already forgot about this post. It was that I needed to do what guramarx shows - make class instance before calling definition.