| 1 |
# https://github.com/godotengine/godot/issues/56702 |
| 2 |
|
| 3 |
func test(): |
| 4 |
const_default() |
| 5 |
func_result_default() |
| 6 |
# calling again will run the initializer again, |
| 7 |
# as the default is not evaluated at time of defining the function (as in python) |
| 8 |
# but every time the function is called (as in C++) |
| 9 |
func_result_default() |
| 10 |
lots_of_defaults("non-optional") |
| 11 |
# somewhat obscure feature: referencing earlier parameters |
| 12 |
ref_default("non-optional", 42) |
| 13 |
|
| 14 |
|
| 15 |
func const_default(param=42): |
| 16 |
print(param) |
| 17 |
|
| 18 |
|
| 19 |
var default_val := 0 |
| 20 |
|
| 21 |
func get_default(): |
| 22 |
default_val += 1 |
| 23 |
return default_val |
| 24 |
|
| 25 |
|
| 26 |
func func_result_default(param=get_default()): |
| 27 |
print(param) |
| 28 |
|
| 29 |
|
| 30 |
func lots_of_defaults(nondefault, one=1, two=2, three=get_default()): |
| 31 |
prints(nondefault, one, two, three) |
| 32 |
|
| 33 |
|
| 34 |
func ref_default(nondefault1, nondefault2, defa=nondefault1, defb=nondefault2 - 1): |
| 35 |
prints(nondefault1, nondefault2, defa, defb) |