godotengine / godotengine/godot-docs

GDScript function parameter default value can be an expression

Open
#8,465 0 comments 0 reactions 0 assignees View on GitHub
area:manual enhancement topic:gdscript
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:**
4.2 built from the repo on linux

**Issue description:**
In the GDScript reference basics page the functions section briefly mentions that function definitions can have typed and optional parameters. What it omits is it can also use an expression as the default value of a parameter. Specifically, another parameter can be referenced as the default value.
I am not sure if there are restrictions in the expressions used as a default value, but I have not seen this even mentioned elsewhere in the GDScript documentation.
As I don't know the breadth of this functionality, I wouldn't be comfortable documenting it, but someone definitely should, as it is really useful.

**URL to the documentation page:**
https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html#functions

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.