Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Nesting Events  (Read 1363 times)

0 Members and 1 Guest are viewing this topic.

AGLAA

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Nesting Events
« on: March 03, 2016, 03:46:14 am »
Hi All , I Am New To SFML and Still Learning .

while i was learning i came across something i don't understand so if anyone would kindly clear things up for me i would be very much appreciated Thank's

The Problem is why i can't use nesting events to check for an Event When another Event Happens Like This :

if (ev.type == Event::MouseButtonPressed && ev.mouseButton.button == Mouse::Left)
          if (ev.type == Event::MouseButtonPressed && ev.mouseButton.button == Mouse::Right)
          {
               leftClick = true;
               rightClick=true;
          }

In TH Previous Example i Check For The Left Key if Pressed and if so i Check For Right Key If Pressed But It
Seems That The 2nd Nested If is never Checked why is This ?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Nesting Events
« Reply #1 on: March 03, 2016, 06:43:36 am »
Your 'ev' variable holds a single event. It can't be two different things at once.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Nesting Events
« Reply #2 on: March 03, 2016, 08:05:38 pm »
To get what you need. You should use some bool's:
bool leftButtonpressed;
bool rightButtonPressed;
 
Or
You can use realtime functions e.g
sf::Mouse::isButtonClicked

 

anything