0 votes

I'm a total noob and I don't understand one thing.

Keeping in account this tutorial: Creating your first script

A variable is a label, so var velocity = Vector2.ZERO means I can write "Vector2.ZERO" instead of "velocity", but when I try to write Vector2.ZERO = Vector2.UP.rotated(rotation) * speed instead of velocity = Vector2.UP.rotated(rotation) * speed I received an error. Why?

Sorry for this very basic question.

Godot version 3.5
in Engine by (14 points)

1 Answer

+1 vote

Overly simplified explanation below...

You can think of a variable as a generic container that can hold some value. That value could be many things, including an integer, a string, or a Vector2 as shown below:

var a = 1
var b = "John Doe"
var c = Vector2.ZERO

However, that Vector2.ZERO reference is a value itself (it's a shortcut for the value Vector2(0,0)). That is, it's already a specific value, just like the number 1 and the string John Doe above. You can't assign a value to something that's not a variable. For instance, none of these will work:

1 = 2
'John Doe' = 'Todd Smith'
Vector2.ZERO = 'apple'

So, while you can store a value in a variable (like the first examples), you can't store a value directly in another value - which is what your original code is trying to do.

by (16,852 points)

Thank you. It sounds simple when explained by an expert, but I couldn't figure it out on my own.

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.