SFML community forums

Help => System => Topic started by: DCurro on May 04, 2014, 07:31:50 pm

Title: Wired controllers "Joystick 0 is NOT connected" but input still accepted
Post by: DCurro on May 04, 2014, 07:31:50 pm
This occurs on both OSX, and Windows.  It occurs for both wired XBox360 and wired Logitech Dual Action.

if(sf::Joystick::isConnected(0)){
        std::cout << "Joystick 0 is connected" << std::endl;
} else {
        std::cout << "Joystick 0 is NOT connected" << std::endl;
}

returns "Joystick 0 is NOT connected".

But, input for the first controller is still accepted, just as normal.  Wireless controllers are recognized properly, though.
Title: Re: Wired controllers "Joystick 0 is NOT connected" but input still accepted
Post by: DCurro on May 05, 2014, 07:26:34 am
I moved this query to after the RenderWindow was created, and it reports proper connection.  I will do further testing, with multiple controllers, on multiple platforms.

EDIT: The CORRECT solution is stated below, by Laurent.
Title: Re: Wired controllers "Joystick 0 is NOT connected" but input still accepted
Post by: Laurent on May 05, 2014, 07:46:18 am
Have you read the big red box at the end of the joystick tutorial?

Quote
Joystick states are automatically updated by the event loop. If you don't have one, or need to read a joystick state (for example, check which joysticks are connected) before starting your game loop, you'll have to call the sf::Joystick::update() function to make sure that the joystick states are up to date.
Title: Re: Wired controllers "Joystick 0 is NOT connected" but input still accepted
Post by: DCurro on May 05, 2014, 08:21:18 am
I read the joystick tutorial from top to bottom last week, when I implemented it.  Never need to call update.  Guess it caught up to me.

Thank you very much Laurent, that answers my question perfectly!