migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
985 stars 55 forks source link

Add support for default parameter values in ClassServices.registerMethod and @Callable macro support #494

Open rktprof opened 1 month ago

rktprof commented 1 month ago

Describe the bug I get a runtime index out of range error in a @Callable function with default parameters (see screenshots). This only happens if I call the function from GDScript with findPlayers(2, 2) and not when filling out all the parameters findPlayers(2, 2, 0, 0)

Also tested this with just one default parameter.

To Reproduce

  1. Create a @Callable function with one parameter that has a default value
  2. Call that function from GDScript without a parameter
  3. See index out of range error

Expected behavior Default values should be used if they are not supplied

Screenshots Original function: Screenshot 2024-06-14 at 10 34 10

Runtime error: Screenshot 2024-06-14 at 10 33 49

Additional context I've only tested this on iOS but I don't see why it would be device exclusive

migueldeicaza commented 1 month ago

Thank you for this bug report!

The issue is that SwiftGodot does not currently register methods with default argument values.

The following fixes need to take place: