• 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!

[Solved] Game does not run when syntax is incorrect?

P

Piyo

Guest
I'm curious as to why the game does not run when I add this code?
I'm fairly certain that it's because of this part: if (xp > (i*10)) {i+=1}

Code:
for (i=1; i<5; if (xp > (i*10)) {i+=1})

{
    if (xp > (i*10))
    {
        lv = i;
        maxxp = (i*10);
        xp = 0;
    }
};
If the syntax is incorrect, then why does GM not notify/pop up an error ?
The reason I know this is because my game ran successfully after deleting the loop. (It didn't run at all before ;w; )
 
What do you mean it doesn't run? Do you get a blank screen? Anything at all in the output box?

That for() statement, while it looks pretty bad and is not the intended usage, is not a syntax error, therefore you won't get a syntax error. It's more like a logic error.

The third part of a for() statement is for incrementing the variable that controls the loop. If you don't increment the variable, the loop will keep running forever I believe. It's just NOT a syntax error.

If xp starts off not being greater than (i * 10), i will never increase, hence an infinite loop.
 
Your third condition on your for loop, the part that is run each time the loop finishes an iteration:
Code:
if (xp > (i*10)) {i+=1}
Means, only increment i if xp is greater than i*10.
So, if the loop is executed with xp less than i*10, that condition will never be true and will run infinitely since i will never be incremented.
 
P

Piyo

Guest
Ahh, thank you guys for clearing the problem!
Indeed, it was a logic, and not syntax error*facepalms* my bad >w< )/

I had not thought of it as an infinite loop at first, as I've created an object which gives xp when destroyed so I assumed that the loop will run once the condition is reached.
 
Top