0 votes

i need help for remove element array
i have script:

var a = ["a", "b", "c", "d", "e"]

func _on_Button_pressed():
var b = a

output is
[a, c, d, e]
[a, c, d, e]

what i want is
[a, b, c, d, e]
[a, c, d, e]

everytime i remove element of b, element of a is removed too
can anyone help me?

in Engine by (14 points)

1 Answer

+1 vote

var b = a is just getting a reference of a
you need to copy of a

var b = [] + a

This code works as you expected, which creates a new array and append a

by (9,776 points)

oh.. Thank you very much

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.