Had a conversation about the lambdas do not
capture local variables issue in LCOLONQ's discord
server. In particular, it was pointed out to me by
@liquidcake1
that the value of
Variant
variables is itself a
reference.
Before, I was mistakenly under the assumption
that Variant
s were passed by reference
and other primitive values were passed by value, but
with this explanation it is now clear to me that
everything is passed by value; it just
happens that the value of a Variant
is
itself a reference. I think this design is less
confusing than any alternative I can think of.
The documentation for Godot 4.2 is also
consistent with this understanding, though it
doesn't talk about how Variant
values
are themselves references:
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: