How do you add and/or subtract values to variables

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Noob_Maker
:warning: Old Version Published before Godot 3 was released.

I am looking for a way to increase (and decrease) values in a variable.
For instance, I have a variable and I want to have the variable to fluctuate in it’s values to cause different things inside a script. Because of that I will have its initial value as0. When one thing happens, I want to add the varuable’s value from a 0 to a 1 or another integer that I would like. And vice versa; subtracting the value of the variable from a 1 to a 0 or from a 0 to a -1.

If anyone know how, I would deeply appreciate it.

:bust_in_silhouette: Reply From: kidscancode

Have you used another programming language before? GDScript works most languages when it comes to this:

var x = 0
# increment x
x = x + 1  # x is now 1
# this does the same thing
x += 1     # x is now 2
# decrement
x -= 1     # x is now 1

The basic overview of GDSCript is a good place to start: GDScript — Godot Engine (2.1) documentation in English

Thank you very much! I had an idea of how it works but I didn’t quite get how it worked :confused:
Thanks anyway!

Noob_Maker | 2017-08-25 21:43