- Edited
When I create a lambda, I would like to be able to set values in the method that is outside of it. You need to be able to do this to use lambdas in patterns like visitors. It's also how they work in languages like C++. The below method prints the output 6 5. I want it to print 6 6 - that is, I want to be able to have foo set to the value the lambda sets it to. This value seems to get reverted after the lambda exits.
Is there a way for my lambda to have the value it sets foo to persist?
# Called when the node enters the scene tree for the first time.
func _ready():
var foo:float = 5
var cb = func():
foo = 6
print(str(foo))
cb.call()
print(str(foo))