SFML community forums
Help => Window => Topic started 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];
-
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).
-
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 :(
-
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.
and I looked and didn't find it in the documentation
I gave you the direct link in my previous post...
-
Are all the keys different types? or what are you trying to say..
sf::Key::Code Controls[4];
-
Are all the keys different types?
No no, they all belong to the same enum.
sf::Key::Code Controls[4];
Correct. You found it ;)
-
Thankyou, I think I got it working :)
<<KillPost<<
-
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.
-
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: 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