0 votes

i made a simple code

extends Node2D
var a
func process(delta):
if Input.is
actionjustreleased("ui_up"):
a =+ 1
print(a)

why the result is always 1?

thank you very much (sorry for bad english)

in Engine by (20 points)
recategorized by

1 Answer

0 votes
Best answer

You wrote

a = +1

Which sets a equal to one. If you want to increase the value of a, use

a += 1

which is equivalent to

a = a + 1
by (19,695 points)
selected by

thank you very much for your answer but it says
"invalid operants 'nil' and int in operator '+'"

Oh, sorry I missed that first part. You never give a a starting value, so how can 1 be added to it? Assign a an initial value.

i undertsand 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 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.