+1 vote

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

in Engine by (450 points)

1 Answer

+1 vote
Best answer

You want to use:

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

See https://docs.godotengine.org/en/3.1/classes/class_dictionary.html#class-dictionary-method-duplicate

by (1,650 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.