Search code examples
if-statementgml

Why is Game Maker Studio telling me that my if statement won't work?


I'm trying to just make a basic clicker game in Game Maker Studios based on this video tutorial, (https://www.youtube.com/watch?v=hEk-oYUKrUQ) and I'm trying to add an if-then statement to an object's code. The code I want to add is as follows:

/*

///Add PS 

if(global.money>=500) (

   global.money-= 500

   global.PS+=5

)

*/

where of course the /* */ s aren't part of the code I am using, only the part inside the /* */ . I've triple checked that all those variables are already defined and on the correct rooms to ensure Game Maker Studios will recognize the variables within this code. I also have triple checked the video to make sure I didn't use parentheses where I was supposed to use brackets or something. My bode matches the code at 4 minutes and 44 seconds into the video I linked above. The code worked for the kid in the video in June this very year and current Game Maker Studios info tells me I'm using the right format even now.

However in the code writer (or whatever it's called, sorry the jargon is foggy in my memory) the syntax checker tells me it expects a ) right in the middle of the += or -= operators thereby telling me (and I've tried work arounds that I can think of) that I'm not allowed to add a command to my then statement even though that's exactly how if then statements work and how they're working in the video. I don't know what else to check here either nor where to go.

Stuff like this is why despite a love for the idea of being a coder I gave up as a child thinking that I needed some expensive fine tooth comb education to get through false information put out by the various tutorials and what not...


Solution

  • You need to put the code - that you want executed when the if statement evaluates true - in between curly brackets (i.e. { and }). So your code would look like:

    /*
    
    ///Add PS
    
    if(global.money>=500) {
    
    global.money-= 500
    
    global.PS+=5
    
    }
    
    */