How can I check if a variable is relative to a number?

I would like to know how to check if a variable is relative to a number in Game Maker. An Example would be:

if variablex += 1
{
DOTHIS
}


However this is not possible in Game Maker so I was wondering if there was some sort of equivalent that I could use.

• if (a == b + 1) – JPtheK9 May 22 '15 at 23:27
• It is unclear what the code is supposed to do, as in other languages, as it currently stands it is an in-place incrementation by one, and a test if it's non-zero. Please elaborate what it is you're trying to achieve. – Lars Viklund May 23 '15 at 5:17
• Thanks JPtheK9, I feel stupid now because that was so simple xD – Cryonius May 23 '15 at 8:19

This expression that you have in your IF is not really an expression. You just add 1 to variablex and it should be true always, meaning that DOTHIS is ran always.

variablex += 1


If structure in GameMaker

if (<expression>)
{
<statement>
}


Say, you have variable x and you need to know if its value is 10:

if (x == 10)
{
DOTHIS
}


To compare x with other var increment:

if (x == y + 10)
{
DOTHIS
}


I suggest that you read the manual once, to get some idea about programming in general. It's not easy stuff, but certainly nothing that you can't handle.

GameMaker manual - If statement

• Katu, I understand what if statements do, if I didn't I wouldn't be writing a game in code. I wanted to check if a variable had an incrementation of +1 rather than re-writing if varaiblex = 1, if variablex = 2 etc. – Cryonius May 23 '15 at 8:18
• Well, your sentence just does not make sense. X is NEVER X + 1. Never, ever. X can be Y + 1. So, you have to compare X to some other number, like is X == 2, is X greater than 2 and less than 4 -> if(X > 2 && x < 4). – Katu May 23 '15 at 10:53

The Syntax of if condition is

if (<expression>)
{
<statement>
...
<statement>
}


But using variablex += 1 means variablex = variablex+ 1 which is always true. Condition should always be variablex==1