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

Author Topic: [Solved] question  (Read 5263 times)

0 Members and 1 Guest are viewing this topic.

buggy123

  • Newbie
  • *
  • Posts: 26
    • View Profile
[Solved] question
« on: December 16, 2009, 06:11:01 am »
I'm getting this error

error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const sf::Input' (or there is no acceptable conversion)
        C:\Documents and Settings\SFML-1.5\include\SFML/Window/Input.hpp(129): could be 'sf::Input &sf::Input::operator =(const sf::Input &)'
        while trying to match the argument list '(const sf::Input, const sf::Input)'

while trying to run this line

Code: [Select]
Input.user_input = Game.App.GetInput();

Here's my class and constructor

Code: [Select]
class CInput
{
public:

const sf::Input& user_input;


CInput(sf::RenderWindow &app) : user_input(app.GetInput())
{
};
};


what's going wrong here

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] question
« Reply #1 on: December 16, 2009, 08:28:10 am »
A reference must be initialized (bound to a variable) at declaration time, you can't make a reference point at another variable after that, unlike pointers.

But that's what you do, so why do you need to assign it again after construction? Do you want to bind it to the input of a different window?
Laurent Gomila - SFML developer

buggy123

  • Newbie
  • *
  • Posts: 26
    • View Profile
[Solved] question
« Reply #2 on: December 17, 2009, 05:56:31 am »
Hmm odd. I'm having some problems. The input seems like it's not updating.

Here's my input class
Code: [Select]
class CInput
{
public:

const sf::Input& user_input;

struct Mouse
{
int mouse_x;
int mouse_y;
bool lmb;
bool rmb;
} mouse;

struct Keyboard
{
bool esc;
} keyboard;

void update_keyboard(void)
{
keyboard.esc = user_input.IsKeyDown(sf::Key::Escape);
};

void update_mouse(void)
{
mouse.mouse_x = user_input.GetMouseX();
mouse.mouse_y = user_input.GetMouseY();
mouse.lmb = user_input.IsMouseButtonDown(sf::Mouse::Left);
mouse.rmb = user_input.IsMouseButtonDown(sf::Mouse::Right);
};

CInput(sf::RenderWindow &app) : user_input(app.GetInput())
{
};

private:

};

CInput Input(Game.App);


And my main loop
Code: [Select]

while(Game.game_state == Game.Menu)
{
Input.update_mouse();
Input.update_keyboard();

if(Input.keyboard.esc)
{
Game.exit();
}

std::cout << Input.mouse.mouse_x << std::endl;
std::cout << Input.mouse.mouse_y << std::endl;

Game.App.Clear();
Game.App.Display();
}


It enters the loops but it seems like the update_mouse and update_keyboard functions is not working. The console writes 0 and when I press escape key nothing happens >_<

I'm guessing it has to do something with the user_input being a reference but I'm not sure

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] question
« Reply #3 on: December 17, 2009, 07:34:13 am »
Can you show a complete source code?
Laurent Gomila - SFML developer

Syphod

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
[Solved] question
« Reply #4 on: December 17, 2009, 07:35:00 pm »
You don't call sf::Window::GetEvent() ?

buggy123

  • Newbie
  • *
  • Posts: 26
    • View Profile
[Solved] question
« Reply #5 on: December 18, 2009, 03:47:08 am »
I'm not using events so I'm not calling GetEvent.

anyways,

Code: [Select]
int main()
{
lua_State* settings = lua.initialize_script("resource/scripts/settings.lua");

Game.initialize_app(settings, "Stick War");

while(Game.game_state == Game.Menu)
{
Input.update_mouse();
Input.update_keyboard();

if(Input.keyboard.esc)
{
Game.exit();
}

std::cout << Input.mouse.mouse_x << std::endl;
std::cout << Input.mouse.mouse_y << std::endl;

Game.App.Clear();
Game.App.Display();
}

Game.exit();
}


and the CGame class

Code: [Select]
class CGame: public CBase
{
public:

sf::RenderWindow App;

int game_state;

enum GameState{
Menu,
Setup,
Ingame
};

//create window
int initialize_app(lua_State* L, std::string app_name)
{
set_fullscreen(L);

if(fullscreen)
{
App.Create(sf::VideoMode(1024, 768, 32), app_name, sf::Style::Fullscreen);
}

else
{
App.Create(sf::VideoMode(1024, 768, 32), app_name);
}

return 0;
};

//call when app is closed
int exit(void)
{
App.Close();
return 0;
};



private:

int set_fullscreen(lua_State* L)
{
fullscreen = CScript::lua_retreive_boolean(L, "Fullscreen");

return 0;
};
bool fullscreen;


};


This is probably horrible coding, but please bear with me, as I'm still a beginner

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
[Solved] question
« Reply #6 on: December 18, 2009, 06:01:36 am »
Doesn't Input depend on Event?

Edit: I'm probably wrong, it's late. :)

buggy123

  • Newbie
  • *
  • Posts: 26
    • View Profile
[Solved] question
« Reply #7 on: December 18, 2009, 06:17:35 am »
Ohhhh I see. So the Input class cannot be on it's own. Got it

Thanks :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] question
« Reply #8 on: December 18, 2009, 09:41:22 am »
Yes you're right actually, sf::Input relies on events and events are handled after a call to GetEvent ;)
Laurent Gomila - SFML developer