if i press a key the result is the same

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DaletWolff

i made a simple code

extends Node2D
var a
func _process(delta):
if Input.is_action_just_released(“ui_up”):
a =+ 1

why the result is always 1?

thank you very much (sorry for bad english)

:bust_in_silhouette: Reply From: kidscancode

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

thank you very much for your answer but it says
“invalid operants ‘nil’ and int in operator ‘+’”

DaletWolff | 2020-04-13 06:21

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.

kidscancode | 2020-04-13 06:23

i undertsand thank you very much

DaletWolff | 2020-04-13 06:30