SFML community forums

Help => General => Topic started by: buggy123 on December 16, 2009, 06:11:01 am

Title: [Solved] question
Post by: buggy123 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
Title: [Solved] question
Post by: Laurent 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?
Title: [Solved] question
Post by: buggy123 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
Title: [Solved] question
Post by: Laurent on December 17, 2009, 07:34:13 am
Can you show a complete source code?
Title: [Solved] question
Post by: Syphod on December 17, 2009, 07:35:00 pm
You don't call sf::Window::GetEvent() ?
Title: [Solved] question
Post by: buggy123 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
Title: [Solved] question
Post by: Oz1571 on December 18, 2009, 06:01:36 am
Doesn't Input depend on Event?

Edit: I'm probably wrong, it's late. :)
Title: [Solved] question
Post by: buggy123 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
Title: [Solved] question
Post by: Laurent 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 ;)