SFML community forums

Help => Window => Topic started by: Weeve on October 20, 2011, 02:02:49 pm

Title: What type is a sf::Key::Down?
Post by: Weeve on October 20, 2011, 02:02:49 pm
I want to make a array to hold 4 keys, but I don't know what type to assign it, so that I can make the array. I'm using C++. example,

(KeyTypeHere) Controls[4];
Title: What type is a sf::Key::Down?
Post by: Laurent on October 20, 2011, 02:07:15 pm
This kind of information is very easy to find, don't waste your time waiting for an answer on the forum ;)

You can look at the function/class that you want to use (most likely sf::Event::KeyEvent or sf::Input::IsKeyDown), and you'll find the type in its declaration.

You can also directly find the declaration of sf::Key::Down in SFML headers (IDEs know very well how to do that for you), or look at the online API documentation (http://www.sfml-dev.org/documentation/1.6/namespacesf_1_1Key.php#ad32ed01d3448273340bd25af5cdd9c81).
Title: What type is a sf::Key::Down?
Post by: Weeve on October 20, 2011, 02:12:00 pm
there was no declaration, SFML has you get a key like this:

sf::Event Event;
while (App.GetEvent(Event)){
  if (Event.Key.Code == sf::Key::Right)
    //do something
}

and I looked and didn't find it in the documentation  :(
Title: What type is a sf::Key::Down?
Post by: Laurent on October 20, 2011, 03:05:19 pm
Quote
there was no declaration, SFML has you get a key like this

The type of Event.Key.Code is the one you're looking for.

Quote
and I looked and didn't find it in the documentation

I gave you the direct link in my previous post...
Title: What type is a sf::Key::Down?
Post by: Weeve on October 20, 2011, 03:10:29 pm
Are all the keys different types? or what are you trying to say..

sf::Key::Code Controls[4];
Title: What type is a sf::Key::Down?
Post by: Laurent on October 20, 2011, 03:13:39 pm
Quote
Are all the keys different types?

No no, they all belong to the same enum.

Quote
sf::Key::Code Controls[4];

Correct. You found it ;)
Title: What type is a sf::Key::Down?
Post by: Weeve on October 20, 2011, 03:38:41 pm
Thankyou, I think I got it working  :)

<<KillPost<<
Title: What type is a sf::Key::Down?
Post by: Nexus on October 20, 2011, 04:27:57 pm
Quote from: "Weeve"
What type is a sf::Key::Down?
decltype(sf::Key::Down) :D

No, there are multiple possibilites to find out the type quickly. If you have a modern IDE like Visual Studio, you can jump to the definition of the type and look at the auto-completion list. Or search in the SFML documentation, maybe you'll find it even faster with Google. Or output the typeid name on console.
Title: What type is a sf::Key::Down?
Post by: Silvah on October 20, 2011, 05:54:21 pm
Quote from: "Nexus"
No, there are multiple possibilites to find out the type quickly. If you have a modern IDE like Visual Studio, you can jump to the definition of the type and look at the auto-completion list. Or search in the SFML documentation, maybe you'll find it even faster with Google. Or output the typeid name on console.
Or my favorite, which is quite handy in debugging heavy template voodoo: define a function like this one:
Code: [Select]
template <typename T>
void showMeTheTypeOf(const T&)
{
  // The always-true condition makes picky compilers like GCC happy.
  // Without it, they report the error too early.
  char forceError[sizeof(T) == 0 ? 1 : -1];
}
Call it, passing the expression you want to know the type of as the argument, and read the compiler's error message, the type will be there :D