0 votes

I define a constant and a variable. I assign the constant to the variable and manipulate the variable but I don't know why the constant also changes.

const DEF = [[0,2],
var deflist
deflist[0][1] *= 1.5

Then the output shows that DEF[0][1] also changes to 3.
It is weird that a constant is not constant even I have done nothing on it.
Does anyone know what happens?

asked Jun 21, 2019 in Engine by edwood (12 points)

1 Answer

0 votes

You need to duplicate with deep=true:

var deflist = DEF.duplicate(true)
deflist[0][2] *= 1.5

Click here to run the code above.

Seems like const doesn't keep arrays from being changed.

answered Jun 22, 2019 by Dlean Jeans (3,733 points)

Oh, I see. Let me try. Thx XD

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 How to use this Q&A? before posting your first questions.