-3
\$\begingroup\$

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ if (a == b + 1) \$\endgroup\$ – JPtheK9 May 22 '15 at 23:27
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Lars Viklund May 23 '15 at 5:17
  • \$\begingroup\$ Thanks JPtheK9, I feel stupid now because that was so simple xD \$\endgroup\$ – Cryonius May 23 '15 at 8:19
1
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ – Cryonius May 23 '15 at 8:18
  • 3
    \$\begingroup\$ 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). \$\endgroup\$ – Katu May 23 '15 at 10:53
0
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.