Reputation: 758
I am testing mouse events in SDL2. I want to print "button" to the console window whenever a mouse button is pressed (right, left and middle button). However, when I move my mouse without pressing any button, the message is also printed. Why is that?
while (!quit)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT:
quit = true;
break;
default:
if (event.type = SDL_MOUSEBUTTONDOWN)
{
std::cout << "button\n";
}
break;
}
Upvotes: 0
Views: 193
Reputation: 10126
You assign value instead of comparison. It must be:
if (event.type == SDL_MOUSEBUTTONDOWN) // was '='
One of the ways to avoid such errors is using of Yoda notation:
if (SDL_MOUSEBUTTONDOWN == event.type)
Upvotes: 1