• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Unexpected unary operator = (Solved)

G

GDevEric

Guest
Hi I'm new to GMS2. I was watching this tutorial video
at around 8:35 I had to stop because of this warning which prevented me from running the game.
upload_2020-1-11_14-13-30.png
I have no idea what i did wrong and don't know how to progress.
 

Attachments

samspade

Member
I believe you just need a space between the five and the negative sign (possibly also the plus). In general, you should use spaces around your operators (+, -, and so on) but it normally won't cause problems. Here though, because - is both minus and negative, the lack of spaces means it is interpreted as a negative sign making that line a bad line of code.

You're also missing parenthesis after the if statement. And you should be using brackets and at least indenting after them as well. You can safely exclude brackets for only a single line, but you should still indent. It will make your code more readable and prevent unintentional errors.

I think all three of the issues I see here are caused by not following some basic code formatting guidelines, which in this case have actually caused errors. I would pay more attention to the actual style and formatting techniques Friendly Cosmonaut uses in these tutorials and try to follow those as well.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
This shouldn’t raise a parser error!! Strange! Try formatting or code correctly, adding braces and parentheses to the if statements
 
G

GDevEric

Guest
Okay I added the spaces and parentheses and the warnings went away. I'll make sure to keep a closer eye on the formatting. Thanks guys
 

slovyan

Member
hello. I also have a problem with this, I followed your advice but nothing worked out.
if (collision_rectangle(x, y, x, y, player, false,false)) && (if keyboard_check(ord("Z"))) {
with Object9 image_index = 1;
else with Object9 image_index = 0;
}
this code should check 2 values. but returns the error "unexpected unary operator &&"
 
hello. I also have a problem with this, I followed your advice but nothing worked out.
GML:
if (collision_rectangle(x, y, x, y, player, false,false)) && (if keyboard_check(ord("Z"))) {
    with Object9 image_index = 1;
    else with Object9 image_index = 0;
}
this code should check 2 values. but returns the error "unexpected unary operator &&"
That code is pretty nonsense, nothing in there is what it should be. For one, you are linking two separate if statements together which is not how you do an and in an if statement, secondly, you are using collision_rectangle() and then using the same coordinates for both points of the rectangle, making it functionally equivalent to collision_point(), thirdly, you are trying to else a with() statement, which is completely wrong. You need to else the if statements, not the with() statement. This might be what you are trying to do, but it's hard to tell from that code:
GML:
if (collision_point(x, y, player, false, false) && keyboard_check(ord("Z"))) {
   with (Object9) {
      image_index = 1;
   }
}
else {
   with (Object9) {
      image_index = 0;
   }
}
 

slovyan

Member
Этот код довольно бессмыслица, там нет ничего, что должно было быть. Во-первых, вы связываете двух операторов, если вместе, что отличается от того, как вы выполняете и затем в операторе, если, во-вторых, вы включаете collision_rectangle(), а обнаруживаются те же координаты для воспаления клеток, что делает его функционально эквивалентным collision_point(), в-третьих, вы пытаетесь else оператором with() , что совершенно неправильно. Вам нужны else операторы if, а не оператор with(). Это может быть то, что вы пытаетесь сделать, но по этому коду трудно сказать:
[код=гмл]
if (collision_point(x, y, player, false, false) && keyboard_check(ord("Z"))) {
с (Объект9) {
изображение_индекс = 1;
}
}
еще {
с (Объект9) {
изображение_индекс = 0;
}
}
[/код]
[/ЦИТИРОВАТЬ]

Спасибо за ваш ответ! это действительно помогло решить еще несколько проблем в других местах. но мне нужно, чтобы это было именно столкновение_прямоугольник, чтобы проверить столкновение с столкновением объекта. Я уже изменил координаты x и y
 

slovyan

Member
[/ЦИТИРОВАТЬ]
Спасибо за ваш ответ! это действительно помогло решить несколько проблем в других ситуациях. но мне нужно, чтобы это было именно столкновение_прямоугольника, чтобы проверить столкновение со столкновением объекта. Я уже изменил координаты x и y
 
Top