Skip to content

Can't compare arrays by reference #33627

Closed
@rokasv

Description

Godot 3.1.1

I want to compare the arrays for uniqueness. I can't do it using array comparison.

var test = [1, 2]
var test2 = test
var test3 = [1, 2]
print(test == test)
print(test == test2)
print(test == test3)

The output is:

True 
True 
True

I expect:

True 
True
False

I want to be able to tell the difference between test2 and test3 as appending new values to test2 will not have them appended to test3.

i.e.

var test = [1, 2]
var test3 = [1, 2]
print(test == test3)
test3.append(4)
print(test == test3)

The output is:

True 
False

I need a way to compare the arrays by reference. There is no way to do it (?).
In other words, how do I get the pre-"fix" #1485 results?

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions