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

Author Topic: What type is a sf::Key::Down?  (Read 4599 times)

0 Members and 1 Guest are viewing this topic.

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
What type is a sf::Key::Down?
« 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];
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
What type is a sf::Key::Down?
« Reply #1 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.
Laurent Gomila - SFML developer

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
What type is a sf::Key::Down?
« Reply #2 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  :(
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
What type is a sf::Key::Down?
« Reply #3 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...
Laurent Gomila - SFML developer

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
What type is a sf::Key::Down?
« Reply #4 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];
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
What type is a sf::Key::Down?
« Reply #5 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 ;)
Laurent Gomila - SFML developer

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
What type is a sf::Key::Down?
« Reply #6 on: October 20, 2011, 03:38:41 pm »
Thankyou, I think I got it working  :)

<<KillPost<<
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
What type is a sf::Key::Down?
« Reply #7 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Silvah

  • Guest
What type is a sf::Key::Down?
« Reply #8 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