Quantcast
Channel: Active questions tagged game-maker - Stack Overflow
Viewing all articles
Browse latest Browse all 189

Unexpected syntax error when using Macro in conditional statement gml

$
0
0

I am very new to Gamemaker, and I am trying to make a simple space invader game. In the player object's step event, I am trying to check for collisions with the left and right sides of the camera. I know this might not be the best way to do this, but I ran into a strange problem while trying to use a Macro variable I defined in the create event. The code below gives me a compile error: "unexpected syntax error" only when I use the macro value in the expression.

collisionLeft = ((x - sprite_width/2) - MOVE_SPEED < 0) ? true : false;collisionRight = ((x + sprite_width/2) + MOVE_SPEED > camera_get_view_width(view_camera[0])) ? true : false;

I have tried swapping out the MOVE_SPEED macro for a number literal and it seems to accept this. I have also tried to storing the left side of the conditional statement in a variable like the code below. The compiler seems to accept this:

var leftArg = (x - sprite_width/2) - MOVE_SPEED;var rightArg = (x + sprite_width/2) + MOVE_SPEED;collisionLeft = (leftArg < 0) ? true : false;collisionRight = (rightArg > camera_get_view_width(view_camera[0])) ? true : false;

I realize there are easy workarounds for this but maybe my understanding of how macros/conditionals work in gml is flawed so any help would be appreciated! Again I am very new to Gamemaker I literally just started yesterday lol.


Viewing all articles
Browse latest Browse all 189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>