When copying a dictionary from another variable they share the same resource, how can I make a copy instead?

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

If I copy a dictionary from another variable, then if I change something about 1 of the variables the other one also changes. How can I avoid that?

Example:

var list = {1:1}
var copy = list
copy.1=2
print(list.1)

This would print 2 instead of 1

:bust_in_silhouette: Reply From: Eric Ellingson

You want to use:

var list = {1:1}
var copy = list.duplicate(true)
copy.1=2
print(list.1)

See Dictionary — Godot Engine (3.1) documentation in English