Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically duplicate a dictionary #38792

Closed
rdmtt opened this issue May 16, 2020 · 2 comments
Closed

Automatically duplicate a dictionary #38792

rdmtt opened this issue May 16, 2020 · 2 comments
Labels

Comments

@rdmtt
Copy link

rdmtt commented May 16, 2020

Godot version:
3.2.1

Issue description:
You need to use the .duplicate(true) function in order to copy the dictionary instead of referencing to it.
With every other value type, it is done automatically (it copies the value instead of referencing the variable itself).

Now, if I want to copy part of the dictionary and make changes to it, the BOTH dictionaries are changed. This has caused me a lot of confusion because I keep forgetting that this one type of value for some reason behaves differently then all the others.

Steps to reproduce:
Create two dictionaries --> assign one to the other --> change one of them --> see the other one change as well.
If you repeat those steps with any other type of value (string, integers, etc.) you won't see this behavior.

Minimal reproduction project:
dict.zip

I know this behavior might be intended but it's not clearly stated anywhere that there is a variable exception such as this. The first time it happened, I discovered this behavior by accident after many, many hours of confusion.

@Calinou
Copy link
Member

Calinou commented May 16, 2020

This is not a bug, but a design decision (passing by reference helps decrease memory usage). The same also applies to Arrays. As far as I know, there are no plans to change this for Godot 4.0.

Note that PoolArrays are passed by value (instead of reference), though. (They were renamed to PackedArrays in the masteer branch).

I know this behavior might be intended but it's not clearly stated anywhere that there is a variable exception such as this.

This is already mentioned in the Array class description, but not yet in the Dictionary class description. I'll add it ASAP.

@YuriSizov
Copy link
Contributor

This is already mentioned in the Array class description, but not yet in the Dictionary class description.

To be fair, it is explicitly stated in the GDScript basics doc.

image

akien-mga pushed a commit to akien-mga/godot that referenced this issue May 18, 2020
huhund pushed a commit to huhund/godot that referenced this issue Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants