-
-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function takes 2 args, should be zero or 1 controller arg #929
Comments
The GE code also fails at inspecting The workaround is to make a wrapper specifically for the GE to inspect: def some_function(controller, b=1, c=2):
...
some_function_controller = lambda controller: some_function(controller)
# or with a regular function:
def some_function_controller(controller):
return some_function(controller) My concern is that it is already a pain to inspect the function from the C++ code. If we can keep it simple and simply provide adapted functions that it will more easily inspected would be the best IMO. |
Moreover, in your code you have parameters, but none of them seems to correspond to a controller, which the BGE is trying to pass. So how would the GE understand what parameter should be a controller or not? Since we are using Python 3.7 now, we could use annotations: def some_function(a: 'controller', b=1):
... But then again, if the function wrapping works for you, I think that it would be better to just do that. In your case, it would look something like the following: def set_player_camera_active(player_cam_name=None, scene=None):
...
set_player_camera_active_controller = lambda: set_player_camera_active() |
@marechal-p ,
Strange, I often use callable classes instead of regular functions.
jiggle bone module: https://pastebin.com/5YFFLsKt I agree with you that code should stay clean. But is that check needed at all ? I suggested approach only to check: (total_args - args_with_defaults) instead of total args.
Of course, there are workarounds, but that seemed to me a one-two lines fix, so I suggested it =) |
Sounds simple enough :)
I looked at your example, |
I got it, thanks. What I thought, is it needed at all to pass controller to Python callable ? |
No idea, but I like the idea that your dependency is passed from the caller, rather than asking for a context info. |
Hello.
Met such issue when tried to launch function
scripts.main.helpers.characters.set_player_camera_active
from Python controller:It's comes from this code:
It checks amount of arguments, but it doesn't account that this arguments can have default values to be able to launch this function and from controller, and from other code.
Suggest to get amount of default values before, than check: how many arguments it requires.
Wrote this in Python-pseudocode as I don't really know CPP (len - function, which returns length of passed to it list or tuple (PyObject)).
So if all defaults provided - function would run normally.
If one arg without default value - that there would be passed controller later.
If more args without default values - error.
The text was updated successfully, but these errors were encountered: