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 / simple code problem

Author
Message
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 18th Apr 2008 16:33 Edited at: 18th Apr 2008 16:35
I'm so tired and I barely keep my eyes open so I think I'll go mad if this isn't gonna work ... first of all here's the small piece of code:



now, the thing that I EXPECT the program to do is this: when I press ENTER for the first time, the program starts to count numbers and when I press ENTER the second time, the counter stops, showing me the last value ... but apparently, it doesn't work please tell me what's wrong cause I'm so damn tired I can't even think right anymore thanks

BTW: I am not looking for a more efficient way of doing this ... I can do that myself but I just want to know what's wrong with this one ... so please post a solution and not an alternative thanks

Could you help me treat my injured Dino-Fly ?
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 18th Apr 2008 16:53 Edited at: 18th Apr 2008 17:07
Perhaps it,




I am troubled, too.
This does not work.
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 18th Apr 2008 18:10
I can't see what the problem is ... I mean I just want to know what the problem is

Could you help me treat my injured Dino-Fly ?
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 18th Apr 2008 18:19
The problem is that when you check the keystate for the second time it is still = 1. Try this instead.



Also I wrote a set of functions to help with key presses see it here http://forum.thegamecreators.com/?m=forum_view&t=107531&b=6

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 18th Apr 2008 18:54
hmm is it still 1 because the time between loops is too short or what ??? thanks for the help

Could you help me treat my injured Dino-Fly ?
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 18th Apr 2008 20:02
does this show what you want to see.




Dark Physics makes any hot drink go cold.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 18th Apr 2008 21:08
Try this.



Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 18th Apr 2008 21:42
ahh thanks guys so the problem was due to speed ... I always analyze my code logically and theoretically, thus forgetting that even if my logic is good, physical aspects such as a very high CPU speed, can affect the results of my calculations ... well I'm human wtf :p thanks a lot !!!

Could you help me treat my injured Dino-Fly ?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Apr 2008 01:31
Quote: "BTW: I am not looking for a more efficient way of doing this ... I can do that myself but I just want to know what's wrong with this one ... so please post a solution and not an alternative thanks"


I almost posted an alternative! Anyway, yes speed is a problem but not the real problem. Any key being read from the keyboard or any mousclick will keep repeating until it is released. You knew that. Human beings can't move as fast as the computer can process the keydown/up events so there will be many repeats. You knew that too. If you bring the computer to the human level by forcing the computer to wait for the human release of the key, you are tying your CPU's hands behind it's back. The computer can still be doing all sorts of things and not waste it's processing power waiting for the release.

You have to let the computer deal with the release at it's own speed. You need to design a toggle switch. The toggle switch will automatically change the state of your test and the computer can go about it's merry business until you change the state again.

the code snippet:

if keystate(28)=1

If fine by itself but will remain 1 until you release it. Everyone already said that. So, you need your own event to change state once when and while keystate(28)=1 for the first flip of the switch. And then change state again for the next flip... and so on

for example:



Get the idea? This will allow the computer to keep doing whatever it wants to do and not be held up waiting for the key release. Maybe you can figure out the way to switch flip back to 0.

This is one example of a toggle. There are easier ways to do this so I'll leave that to you.

Sometimes though, you'll want everything to halt until the key is released - like in an application when you are selecting a menu item or responding to a messagebox. So in those case using WHILE or REPEAT may be ideal. But for a simple start and stop, you'll most likely want to implement a toggle switch.

Enjoy your day.
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 19th Apr 2008 08:53
yeah, that's what I was doing always it's just that yesterday I didn't see the problem as I said, I was so damn tired I couldn't even hold my eyes open so that's why I asked for help cause I knew I wouldn't see it in general, what I do is have a variable which acts like an ON/OFF switch so when I press ENTER, the variable is ON and I can't press another ENTER until it's OFF again ...

Could you help me treat my injured Dino-Fly ?

Login to post a reply

Server time is: 2024-11-25 06:28:45
Your offset time is: 2024-11-25 06:28:45