Skip to content
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

Fix optional parameters for commands #59

Merged
merged 2 commits into from
May 24, 2024

Conversation

spirifoxy
Copy link
Contributor

When declaring commands with optional parameters, calling them omitting those parameters throws an exception.

Example:

 _dialogueRunner.AddCommandHandler<string, string>("Scene", Scene);
...

 private void Scene(string imageName, string alignment = "center") {
    ...

Calling this command as <<Scene village_intro>> will lead to this:

object System.Reflection.MethodBase.HandleTypeMissing(System.Reflection.ParameterInfo, System.RuntimeType): System.ArgumentException: Missing parameter does not have a default value. (Parameter 'parameters')
  <C++ Error>    System.ArgumentException
  <C++ Source>   :0 @ object System.Reflection.MethodBase.HandleTypeMissing(System.Reflection.ParameterInfo, System.RuntimeType)
  <Stack Trace>  :0 @ object System.Reflection.MethodBase.HandleTypeMissing(System.Reflection.ParameterInfo, System.RuntimeType)
                 :0 @ object System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
                 :0 @ object System.Delegate.DynamicInvokeImpl(System.Object[])

The fix is to send those default values directly instead of Type.Missing

@dogboydog
Copy link
Collaborator

Nice! I tested and it works great. Also still works if you override the default value. Thanks. Will release as 0.2.8

@dogboydog dogboydog merged commit d0c95d7 into YarnSpinnerTool:develop May 24, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants