How to set deferred on a dictionary?

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

Lets say you have a dictionary

var dict : Dictionary = {}

Lets say you wanted to set_defer a value.

The way I am aware of how to do this is like such…

func _ready():
var key = "Key"
var value = "Value"
call_deferred("set_deferred_dict",key,value)

func set_deferred_dict(key,value):
  dictionary[key] = value

However, I would like to know if it is possible to do this via the set_deferred

Is it possible to do something like

set_deferred("dict",???)
:bust_in_silhouette: Reply From: Haydoggo

Dictionary isn’t an Object and has no properties, so cannot be used with set_deffered by itself.

Although because you’re using Godot 4, you can achieve more or less the same one liner by using a lambda:

var dict := {}
var key = "Key"
var value = "Value"

func _ready():
	(func(): dict[key] = value).call_deferred()