Error: Expected end of statement (“var”), got ‘:’ instead

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Venex2004

Am new to Godot and was reading the Godot doc and came across lambda functions. But it keeps returning some error, which i don’t know why. I have checked for solutions but didn’t have any luck. Here my code:

func _ready():
     var my_lambda = func(x): print(x)

My error seems to be after the function parentheses.
Also tried other lambda functions still no result.
Thank you .

:bust_in_silhouette: Reply From: Enfyna

Lambdas are implemented in 4.0. This code works in 4.0.

func _ready():
    var my_lambda = func(x) : print(x)  # Prints 10

You can look at this answer if you want to use something like lambda in 3.5 :