mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
Merge pull request #8730 from Marenz/patch-1
Lambdas need an explicit `return`
This commit is contained in:
committed by
Max Hilbrunner
parent
2b3bc6d530
commit
42035c7796
@@ -1347,6 +1347,12 @@ Lambda functions can be named for debugging purposes::
|
||||
var lambda = func my_lambda(x):
|
||||
print(x)
|
||||
|
||||
Note that if you want to return a value from a lambda, an explicit ``return``
|
||||
is required (you can't omit ``return``)::
|
||||
|
||||
var lambda = func(x): return x ** 2
|
||||
print(lambda.call(2)) # Prints `4`.
|
||||
|
||||
Lambda functions capture the local environment. Local variables are passed by value, so they won't be updated in the lambda if changed in the local function::
|
||||
|
||||
var x = 42
|
||||
|
||||
Reference in New Issue
Block a user