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 Discussion / Gosh, Key Input Problem (wow)

Author
Message
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 25th Oct 2005 03:41 Edited at: 25th Oct 2005 03:41
I want it so when I press a key, and triggers a save file, it doesn't keep saving the file. For example:

savecount#=1
If upkey()=1
Dim Save$(2)
Save$(1)="Blah1"
Save$(2)="Blah2"
save array "File "+str$(savecount#)+".txt",Save$(1)
inc savecount#
endif

In that example, it will save the file many times until you stop pressing the up key. I want it to only happen once. How would you do that? I mean, you cant force the upkey() parameter to be 0 or something...
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 25th Oct 2005 05:16 Edited at: 25th Oct 2005 05:17
Just put most of that into a IF-THEN statement.



The SaveCount = 0 has to be outside the loop, otherwise it will be set to 0 every round!

Try spacing your operators out and using capitalization more often, it takes a bit longer to write but when it's time to read back over your work it makes it a lot easier.

But... I don't recognize that Save Array thing, was that pseudocode or did I spend too much time with other languages?

Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 25th Oct 2005 11:47
save array is valid command.

as for Xeno`s problem, all you need to do is to wait for the user to release the key before doing anthing else after the save, eg

savecount#=1
If upkey()=1
Dim Save$(2)
Save$(1)="Blah1"
Save$(2)="Blah2"
save array "File "+str$(savecount)+".txt",Save$(1)
inc savecount

rem loops endlessly until up key is released
repeat
until upkey()=0

endif

also savecount would be better as a integer, unless you save files as file1.01.txt, file4.32.txt etc, just use integers and save em as file1.txt file2.txt etc.



Tyger software
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 26th Oct 2005 00:29
I wouldn't suggest that method, Me!, unless it didn't matter that the whole program grinds to a halt until you lift up the key.

Setting and checking the value of SaveCount allows the rest of the program to run while the user has the key down, but still only saves once.

Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 26th Oct 2005 14:31 Edited at: 26th Oct 2005 14:41
Pretty much what P Schnell said, but in different words:



This is called debouncing a key - it will let you press up to do your thing, but will not let you do it again, until you let go of the key and press it again.

P Schnell just forgot to put the bit in about setting it back to 0 when the key wasn't being pressed, is all.

[edit] That's if you want to be able to do it more than once while the program is being run. Otherwise, P Schnell's was perfect for your needs.

Login to post a reply

Server time is: 2025-05-22 13:25:12
Your offset time is: 2025-05-22 13:25:12