Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Make a varible keep its value outside of the IF statement

Author
Message
Mr Bigglesworth
18
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 25th Feb 2011 01:16
Hey guys, I am making a menu and when the player presses escape, it sets a varible to show the menu. It makes the varible equal 1 when the escape key is pressed, but the varible only has a value of 1 while the escape key is being pressed, not after it was pressed.

So, how can I make the varible retain its value after the escape key was pressed.

LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 25th Feb 2011 04:40
Place the value of escapekey() into a variable. Like this:


Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 25th Feb 2011 09:32 Edited at: 25th Feb 2011 09:32
It's probably working right but toggling the menu on/off 40+ times from pressing ESC once. To stop that from happening with your switch you can do it in 3 ways.

1. Stop all action till the user lets go of ESC button.




2. Use a TIMER() to prevent the switch from instantly turning off. Change the amount of time to suit your needs (holding down ESC here will toggle the switch every 500 milliseconds).




3. The coolest method is using the GET KEY STATE() command that is an actual toggle for many keys. Pressing ESC once will toggle it on and pressing it again will toggle it off. No need to use TIMER() or freeze the action. You can use the GET KEY STATE() of the ESC button itself as the Menu toggle instead of using a variable switch.



Login to post a reply

Server time is: 2026-07-17 13:57:36
Your offset time is: 2026-07-17 13:57:36