Godot-docs: One step vs two step builtin in a container modification is not equivalent

Created on 29 Apr 2018  路  4Comments  路  Source: godotengine/godot-docs

Sorry for the obscure title, here is a snippet that would explain much better:

var a = [Vector2()]
a[0].x = 42
var b = a[0]
b.x = 43
print(a)  # Returns [Vector2(42, 0)]
# Same behavior with Dictionary and Pool*Array :'-(

I've encountered this behavior while working on Godot-Python (see https://github.com/touilleMan/godot-python/issues/93 for a more in-depth explanation of the reason of this behavior).

I'm not sure this behavior has to be corrected (I would guess the cost would be high given it deals with internal implementation of containers and I didn't see other issue about this...). However we could add a line about this exotic thing in the GDscript documentation when talking about containers.

enhancement

Most helpful comment

Vector2 is a value type, so what you are doing is expected. b is not a reference to the item in the array, and doesn't need to be.

All 4 comments

Vector2 is a value type, so what you are doing is expected. b is not a reference to the item in the array, and doesn't need to be.

Indeed, as far as I know this is expected behaviour.

Just read the last line, yeah this could be made clearer in the docs.

Moving to godot-docs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcmonkey picture jcmonkey  路  4Comments

KoopHauss picture KoopHauss  路  3Comments

golddotasksquestions picture golddotasksquestions  路  3Comments

RiverMesa picture RiverMesa  路  4Comments

cbscribe picture cbscribe  路  5Comments