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.

Dark GDK / question about arrow keys

Author
Message
penguinth
16
Years of Service
User Offline
Joined: 11th Aug 2008
Location:
Posted: 12th Aug 2008 00:34
I'm just fooling around with dark gdk and c++ and i was trying to do a text-based room to room kind of thing (like a mud). I'm using the arrow keys to move but it keeps moving too fast. for example if rooms 1 through 5 are going down and I press the down key it skips from 1 right to room 5 instead of going to 2. Just wondering if there is a way to stop this. I've used dbWait but it seems to always go too fast or too slow.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 12th Aug 2008 02:27
I use a delay variable. I increment it each iteration, and only accept input once it's reached a certain value. Then, I reset it to 0, and check for input.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 12th Aug 2008 04:39
As long as the key is held down you're going to have a positive result each time through your loop. You might need to maintain a boolean flag to track if the key press has already been detected. If it has, ignore any of that key press until it's released at which time you reset the boolean to false and it lets you detect the next time the key is pressed. Since you're using functions to check for the key press it would be easy to have each checkXXXX function contain a boolean as a static variable so it retains its value from one function call to another



There's still some fault with this code since it may depend on when and where in the code it gets called. But if it's in a fairly tight loop it should be okay for your purpose. Now you have to modify the code for the other four functions.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 12th Aug 2008 17:42 Edited at: 12th Aug 2008 17:42
To be safe, I would implement this system directly, rather than with a generic function. Though testing could decide whether the function would suffice.


My site, for various stuff that I make.
Skull breaker
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 3rd Sep 2008 06:49
also if u want to write a mud i suggest using
instead of using dark GDK. just use normal C++ generic library

This is a signiture

Login to post a reply

Server time is: 2024-09-30 05:41:16
Your offset time is: 2024-09-30 05:41:16