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 / Checking TIMER inside input poll vs. outside?

Author
Message
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 21st Sep 2011 18:43
I was working on a part of my game, which required timer-related input (it would only accept input after a certain number of seconds).

When I tried



it would always do the GOSUB regardless of if a second has passed or not.

However when I tried



It worked as it should: It would only GOSUB after 1 second has passed.

Can anyone please explain why it wouldn't work the previous way and why the latter way would work? Either way, it seems it should have the same end result which is to wait a second.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Sep 2011 19:07
Where do you set up prev_timer?

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 21st Sep 2011 20:42
I set it up in my previous ran event when the person hits the space key to exit it.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Sep 2011 20:50 Edited at: 21st Sep 2011 20:52
Your second timer is missing the brackets (). But the bug seems to be when you setup the prev_timer.

This is easier..

t = timer() + 1000
do
IF t<= timer()
IF SPACEKEY() = 1

GOSUB _event
ENDIF

ENDIF
loop
Then you can see the setup, and the code in one place.

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 22nd Sep 2011 04:24 Edited at: 22nd Sep 2011 04:25
Whoops, the brackets were included in the original code. >_< But yeah, I think you're right. Thanks. I thought it looked normal like that.
Sequence
15
Years of Service
User Offline
Joined: 16th Mar 2011
Location: Canada
Posted: 22nd Sep 2011 09:24
In the first one, it checks the spacekey() and ONLY THEN checks the timer result, while in the second one, it ONLY checks the spacekey() IF the timer has passed 1000. The second one is better.

In the second one, the timer MUST pass 1000 before it will ever look at the key and do the Gosub.


And, as said, the brackets are missing which may have led to the problem anyway.


How about this?

t = timer() + 1000
repeat : Until t<= timer()
repeat : Until SPACEKEY() = 1
GOSUB _event

If all the "1"s are in the right place, it'll work like a charm.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 22nd Sep 2011 18:11
Hi Sequence,

I generally would have done that or a "WAIT KEY" command, but since I'm setting up my code for when I put in multiplayer functionality (which should be next week if not tomorrow), I can't have any real pauses in the game in case packets are being sent to it (If that makes sense).

Login to post a reply

Server time is: 2026-07-10 20:57:51
Your offset time is: 2026-07-10 20:57:51