Add A Value To A Variable [SOLVED]

Z

Zephyr Schwarzwolf

Guest
Hi everyone !

For an integrated variable as "x", "y", or "depth", if you set :
Code:
"that_variable" = "that_variable" +- "value"
It increase or decrease with a speed of "value".

My question may seem a lil silly, but I'm unable to simply add a number to theses variables. (Don't think that's the case with local and global var. I don't remember to have tried)
I tried to set something like :
Code:
"that_variable" +- "value"
But it tells me that the variable is used as a function !
So, how to ?

Thank ya in advance !
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, you almost have it... :)

You want to do this:

Code:
myvar += 10;
myvar -= 20;
That will add or subtract a value from the "myvar" variable. Note too, that you can increment/decrement by 1 by simply doing:

Code:
myvar++;
myvar--;
++myvar;
--myvar;
The above will add or subtract 1 from the "myvar" variable. To see why there are different ways to do this, check the section on "Expressions" in manual: https://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/3_gml_overview/12_expressions.html
 
Z

Zephyr Schwarzwolf

Guest
I feel stupid... I thought "var += val" and "var = var + val" was the same... Now, I know the difference ! Thank you very much ! :D
 
Top