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.

Newcomers DBPro Corner / How to make a loop thats checks for a hotkey to be pressed then goes to a menu?

Author
Message
Kraken
15
Years of Service
User Offline
Joined: 11th Jun 2009
Location: South Carolina
Posted: 17th Jul 2009 05:26
I am creating a basic text game where the player types in things, and the game responds to there anwsers.

My question is, how do you make a loop that is always running so that the game continuously checks if you press a key on the keyboard, and if you do press it, it will bring up a game menu, and I'll be able to go back to the line where I went to the menu from,
e.g. if I press "resume" on my game menu, it will go back to where it left off.

Do epic stuff.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 17th Jul 2009 06:55 Edited at: 17th Jul 2009 06:57
You can do that by checking the KEYSTATE() of a key and go to a function if that key has been pressed. When the function is over it goes back to the line after the function call. You can also use GOSUB to do the same thing... just don't use GOTO... ever.



zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 17th Jul 2009 17:17
I assume that you are using the INPUT command for the text input. such as:



I don't know if you can set DarkBasic to catch keyboard or mouse interrupts when it is waiting for a user response from an INPUT command. A work around would be to set the 'name$' variable(in this case) to respond to "menu" or some such string.

Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 17th Jul 2009 19:44 Edited at: 17th Jul 2009 19:44
One piece of advice - dump the idea of using Input as your method of communicating with the user. Learn how to build your own text buffer (hint: search for 'text buffer' on the forums). Using a text buffer, your program will already be in a loop and you can check for, let's say, the keystate of F1 each loop and go to a menu function while the text buffer is still has some text in it.

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Kraken
15
Years of Service
User Offline
Joined: 11th Jun 2009
Location: South Carolina
Posted: 18th Jul 2009 00:47
Thanks everyone, I think I am going to go with Dream and Death's idea.

Do epic stuff.

Login to post a reply

Server time is: 2024-09-28 08:27:06
Your offset time is: 2024-09-28 08:27:06