0 votes

HI everyone.
I am quite a newbie for programming and also Godot

so I just wonder about Godot variable stores the actual object or its pointer reference.

for instance
if i have an object called "SomeObject" and it has a property a = 1, so I assign it to variables item1 and item2

var item_1 = SomeObject
var item_2 = SomeObject

print(item_1.a)
# 1

item_2.a = 100

print(item1.a)
#??? what will be printed 1 or 100 ? 

thanks in advance for your answers.

in Engine by (28 points)

1 Answer

+2 votes
Best answer

It will print 100. Objects, Arrays and Dictionaries are passed by reference, while primitive types like int, bool, float, Vector2, Vector3, Transform2D and Transform are passed by value.

by (27,902 points)
selected by
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.
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 webmaster@godotengine.org with your username.