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 / Really simple question

Author
Message
Zeus6191
14
Years of Service
User Offline
Joined: 24th Oct 2011
Location:
Posted: 25th Oct 2011 00:30
For some reason the following loop won't exit unless the return key is held. When it is just pressed the loop continues; Any suggestions?


REM Game Start Screen

Rem Insert Game Start Image

REM FLASHING Game Start text

DO

SET TEXT TRANSPARENT
CENTER TEXT 320,400, "HOLD RETURN"

WAIT 300

SET TEXT OPAQUE
CENTER TEXT 320,400, " "

WAIT 300

if RETURNKEY() = 1 then exit

LOOP

The same is true for the following example:
Loop

SET TEXT TRANSPARENT
CENTER TEXT 320,400, "HOLD RETURN"

WAIT 300

SET TEXT OPAQUE
CENTER TEXT 320,400, " "

WAIT 300

if RETURNKEY() = 1 then
ReturnConfirm = 1
end if

until ReturnConfirm = 1

Any suggestions?


---------------------
What the h4x...
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 25th Oct 2011 01:08
Try this:



Cheers.

I'm not a grumpy grandpa
Zeus6191
14
Years of Service
User Offline
Joined: 24th Oct 2011
Location:
Posted: 25th Oct 2011 01:22
Quote: " Posted: 24th Oct 2011 17:08 | link | toggle


--------------------------------------------------------------------------------
Try this:

+ Code Snippet
DO

SET TEXT TRANSPARENT
CENTER TEXT 320,400, "HOLD RETURN"

WAIT 300

SET TEXT OPAQUE
CENTER TEXT 320,400, " "

WAIT 300

if RETURNKEY() = 1 then go=1
if go=1 then exit

LOOP

Cheers.


"


This is not meant to be rude.

If you see my second set of code it is very similar. I have tried your snippet and I have the same issue. The program only exits the loop when the key is held; if i press the key the loop continues.


---------------------
What the h4x...
Zeus6191
14
Years of Service
User Offline
Joined: 24th Oct 2011
Location:
Posted: 25th Oct 2011 01:29
I've found the problem. It appears the program does not accept input while the progaming is "wait"-ing. Is there another command that pauses the program other than "sleep". Sleep does not work either.

Unless someone has some another algorthim they could suggest.


---------------------
What the h4x...
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 25th Oct 2011 01:31
If you press and release the return key while the program is "waiting", it will not be caught by the call to returnkey().

In essence, that loop will run one cycle in 600+ milliseconds (which is < 2 FPS), so it's kind of slow to accept fast input.
You could use the timer() function to see whether the appropriate amount of time has passed or not and let the loop run a lot faster, thus (much more likely at least) catching your quick hits of the return key.

All the "...key()" functions return true (1) if the particular key is held down at the moment when the function is called (and false (0) otherwise).


"Why do programmers get Halloween and Christmas mixed up?"
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 25th Oct 2011 12:26 Edited at: 25th Oct 2011 12:28
Quote: "This is not meant to be rude. "


Not at all. It was just a misunderstanding .You should put your piece of code between brackets

Cheers.

I'm not a grumpy grandpa
Braude Interactive
19
Years of Service
User Offline
Joined: 1st Aug 2006
Location: Sheffield, UK
Posted: 25th Oct 2011 12:47
I'm sure there's a way of doing it using the buffer... but it's been so long since I've used DBPro I can't remember what to call...
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 25th Oct 2011 13:15 Edited at: 25th Oct 2011 13:16
Yeah like Rudolpho said it's best to use make a TIMER() so it can run without the need for the WAIT command. You can use a simple switch (on/off) to toggle between showing the text and erasing it.



Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 25th Oct 2011 19:52
The reason it pauses is because your pausing the program with the wait command.

Try this.




I like games, and stuff.

Login to post a reply

Server time is: 2026-07-11 09:48:57
Your offset time is: 2026-07-11 09:48:57