Jump to content
  • Advertisement
Sign in to follow this  
Adam West

simple c++ bool question

This topic is 2234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there.

this is a snippet from my game engine which handles the key being pressed down.


void redNovember::inputHandle()
{
if(receiver.IsKeyDown(irr::KEY_ESCAPE))
showGameMenu = true;
else
showGameMenu = false;


//menu shit
if (showGameMenu == true)
{
SYS->showInGameMenu();
}
else

SYS->hideInGameMenu();

};


the problem is i want to keep showInGame running until the escape key is pressed again, how would i go about doing this?

Share this post


Link to post
Share on other sites
Advertisement
you need to "toggle" ShowGameMenu if I understand your intentions.
This means whenever the appropriate key is pressed, change its state from true to false or vice-versa (if the input is event based). If you poll the input state, then the problem becomes a bit more complex, since you have to store the state of the key separately. Edited by szecs

Share this post


Link to post
Share on other sites
just tried this so now it stays down, i thought this might work with releasing it again but no dice.


void redNovember::inputHandle()
{
if(receiver.IsKeyDown(irr::KEY_ESCAPE))
showGameMenu = true;
while(showGameMenu == true)
{
SYS->showInGameMenu();
if(receiver.IsKeyDown(irr::KEY_ESCAPE))
showGameMenu = false;
}

};

Share this post


Link to post
Share on other sites

void redNovember::inputHandle()
{
if(receiver.IsKeyDown(irr::KEY_ESCAPE))
showGameMenu = !showGameMenu; //invert current value, this should let you toggle between true and false by pressing esc.

//menu shit
if (showGameMenu == true)
{
SYS->showInGameMenu();
}
else
SYS->hideInGameMenu();

};

This should do it.

But I don't know how the rest of your app works.

Share this post


Link to post
Share on other sites
In the same line as what Shenaynay just posted, instead of writing

if(receiver.IsKeyDown(irr::KEY_ESCAPE))
showGameMenu = true;
else
showGameMenu = false;


you can do

showGameMenu = receiver.IsKeyDown(irr::KEY_ESCAPE);

Share this post


Link to post
Share on other sites
i don't really understand the IEventReciever stuff. but all i want to do is that when escape is pressed it will open the gui and it wont close it until escape is pressed again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!