• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Value subtraction?

M

MintyPretzel126

Guest
So I have this code here:
Code:
///Take Away Lives
lives - 1
How do I properly subtract the value? Thanks a bunch, even if you just read.
 

FrostyCat

Redemption Seeker
Short form:
Code:
lives -= 1;
Long form:
Code:
lives = lives - 1;
If you want to actually change the variable's value, use -=. If you don't but still want to know what the result would have been, use -.
 
K

Kijjum

Guest
Thanks for the quick reply! I'm having a little trouble with the lives starting at the wrong value right now, so I'll reply once I get that fixed.
In the creation code of your character put lives = (number of lives you begin with);
then you can call to that variable in other actions like a collision with a bullet or something lives = lives - 1;
 

TheouAegis

Member
Shorterhand:

lives--;

or

--lives;

Although it can make code less legible for some people if they aren't used to it. And the two are sliiiiiightly different in that they can both be used in-line and will read and write to lives at the same time even in the middle of code, but the value used will be the previous value if -- is put at the end, or the next value if -- is put at the beginning.

E.g.:

lives = 4;
cat = lives--;
dog = --lives;

cat will be 4, while dog will be 2. cat is set to lives before it is decreased, then lives will be decreased (from 4 to 3); dog is set to lives after it has been decreased again (from 3 to 2).
 

Carolusclen

Member
Shorterhand:

lives--;

or

--lives;

Although it can make code less legible for some people if they aren't used to it. And the two are sliiiiiightly different in that they can both be used in-line and will read and write to lives at the same time even in the middle of code, but the value used will be the previous value if -- is put at the end, or the next value if -- is put at the beginning.

E.g.:

lives = 4;
cat = lives--;
dog = --lives;

cat will be 4, while dog will be 2. cat is set to lives before it is decreased, then lives will be decreased (from 4 to 3); dog is set to lives after it has been decreased again (from 3 to 2).

doesn't matter how long a person uses GM, you learn something new every day... i was not aware of this haha :p
 
Top