How to skip a middle argument?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

I had never wondered anything about this, but how could I skip arguments when calling a function?

For example:

func _ready():
    my_function(4, b, 6) # How to skip 'b' argument?

func my_function(a = 1, b = 2, c = 3):
    return a + b + c
:bust_in_silhouette: Reply From: tastyshrimp

I don’t think that is currently possible in GdScript. This is usually made possible by named arguments which is a functionality in many programming languages but not yet supported in GdScript. I believe this pull request is the one you should follow to track when it gets implemented/merged.

You can do a manual implementation of it if you really want, the way to do it is to have your function receive a dictionary as a parameter and you check if they were passed or not to decide if you want to use the default or not. But it might get annoying with having to build a dictionary every time you want to call the function.