I had no idea how to summarise the problem in the title so I'll try better here.
I'm making something that looks like a menu of sorts.
In the first screen you choose a location and it operates when boolean variable loc_chosen is false. If you choose one and press enter it changes to true.
Then while loc_chosen is true another block of instructions can be executed in which you choose one of two options and when you press enter another boolean variable job_chosen changes from it's initial false to true. Then another block of instructions can be executed.
Outside of the loop is code for showing each "screen".
So when loc_chosen is false you can change between options, if you choose one the screen is grayed out and another set of options appear for loc_chosen being true.
That works fine but when I adden another boolean variable - job_chosen, that should change into true only after choosing an option on a previous screen everything went wrong.
It suddenly displays the last screen and somehow along the way job_chosen changes to true before I make that choice.
The moment I press enter on the first screen it immediately skips over next block of instructions and changes job_chosen to true. I've only just started using a debugger so I can't really locate the problem. It seems like the moment loc_chosen changes to true pressing enter carries over to the second block of instructions and triggers job_chosen = true. Im sorry for such a long post, but if anyone has an idea on how to fix it, it would mean a world to me.
if (event.type == sf::Event::KeyPressed)
{
if (!loc_chosen)
{
switch (event.key.code)
{
case sf::Keyboard::Down:
{
if (location < 3) { location++; std::cout << location << std::endl; } break;
}
case sf::Keyboard::Up:
{
if (location > 0) { location--; std::cout << location << std::endl; } break;
}
case sf::Keyboard::Return:
{
st_number += std::to_string(location);
std::cout << "LOC NUMBER: " << st_number << std::endl;
loc_chosen = true; break;
}
}
}
if (loc_chosen)
{
std::cout << linia_loc[location * 2] << std::endl;
std::cout << linia_loc[(location * 2) + 1] << std::endl;
switch (event.key.code)
{
case sf::Keyboard::Up:
choice = 0;
break;
case sf::Keyboard::Down:
choice = 1;
break;
case sf::Keyboard::Return:
st_number += std::to_string(choice);
std::cout << "LOC + CHOICE NUMBER: " << st_number << std::endl;
job_chosen = true;
break;
}
}
/// here is the code for showing the different screen and on the bottom is
/// this code for drawing stuff when job_chosen is true
if (job_chosen)
{
App.draw(s_gray);
App.draw(text_box);
} // this code gets exacuted immidiately after the first enter