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

Author Topic: Input usage out of scope  (Read 1568 times)

0 Members and 1 Guest are viewing this topic.

Cyntalan

  • Newbie
  • *
  • Posts: 2
    • AOL Instant Messenger - Cyntalan
    • View Profile
Input usage out of scope
« on: August 18, 2008, 07:39:26 pm »
Maybe I'm confused on the whole process of how I should be using it, but the reference information provided left me with slightly vague usage in my confusion. Not to mention this has got to be something that has been done before, as no one REALLY makes their entire program in one giant main. :lol:

The reference documentation and tutorials for the whole process of declaring and using sf::Input seems to rely on being called within the scope of a single function. Is there a method in which this class type can be declared out of scope and loaded within a function for other functions to use? Maybe this is something a little rudimentary, but I'm totally at a loss at this point.

What I'd like to do is something akin to:

Code: [Select]

sf::Input *Input;

void initInput(sf::RenderWindow *a)
{
   Input = a->GetInput();
}


But it claims to want a constant, which means I can't exactly declare it out of scope AND load it. Is this the wrong way to go about it, or is there a way to do this? Or should I just be calling this in scope at the beginning of each function I need it in, with it being destroyed at the end of the function?

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Input usage out of scope
« Reply #1 on: August 18, 2008, 08:35:57 pm »
I didn't quite get what you mean, but sf::Window::GetInput returns a const reference (think of it as a kind of pointer) to the sf::Input object that is a member of sf::Window. It gets updated when you call sf::Window::GetEvent.

Cyntalan

  • Newbie
  • *
  • Posts: 2
    • AOL Instant Messenger - Cyntalan
    • View Profile
Input usage out of scope
« Reply #2 on: August 18, 2008, 08:46:52 pm »
So I guess what I was getting at is that this is something that's meant only to be declared in scope. Declaring the standalone input variable within any function that needs it.

Basically, calling the line sf::Input &Input = App.GetInput(); at some point in the beginning of any function that would like to use it. Is that about right?

 

anything