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 / if a specific key is pressed

Author
Message
Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 27th Apr 2003 14:11
in dbp, how do i perform a specific action when a specific key is pressed. For example when someone presses k it would print a text and if someone presses e then the program exits etc. Please help
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 27th Apr 2003 14:12
pseudo-code:
if scancode(from e)=1 then end
if scancode(from k)=1
print text$
...
endif

God is real, unless declared integer.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Apr 2003 15:36
Almost ... replace 'scancode' with 'keystate' and you've got it
Kentaree
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 27th Apr 2003 15:47
An easier method to find if a alphanumeric (number or letter) key is being pressed, is to use inkey$. For example, to end a program when someone presses the `q` key, you can use:

if inkey$()="q" then end

This is somewhat more intuitive than keystate and it makes it easier to read over the code later on.

Whatever I did I didn't do it!
Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 27th Apr 2003 18:56
i set so that if one presses l then it would print one thing and if someone would press k then it would print something. But when someone presses one thing the program performs the action assined to the button and the program exits. I want to stop this! but how! i want the program to continue until one presses esc. PLZ HELP!!!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Apr 2003 19:36
Code? Without know what you are doing, we can't tell you where you are going wrong.

@Kentaree - Inkey$ is great in it's place (basic text input) but it can't deal with multiple simultaneous keypresses. That's why I suggested Keystate.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 28th Apr 2003 03:13
You need to use a loop or the goto command.. with a loop..

CLS
DO `start the loop
if inkey$()="k"
print "Hey"

if inkey$()="j"
print "Yo"
else
if inkey$()="esc" `think that is the escape character
END `quit program
endif
endif
endif `For every if make sure there is an endif
LOOP `start the loop again

With the goto command
_goto1:
wait key
if inkey$()="k"
print "Hey"
goto _goto2

_goto2
wait key `wait for key to be pressed
if inkey$()="j" `if the key been pressed is j
print "Yo" `print to screen you
goto _goto1 `goto jump point _goto1
endif

I would stick to the loop method however.
Please correct me if I am wrong people, only bought the DBP book less then a month ago.

I hear and I forget. I see and I remember. I do and I understand.
Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 28th Apr 2003 16:10
Nilrem, none of ur code works as i want them to. In ur loop code, if one presses the button, it prints it thousand times. So i think even doing a simple thing in db is like immpossible. I will need to use buttons then!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Apr 2003 19:47
So change the code then.

Inserting something like this would remove the repeats completely.



Now whats so hard about that?
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 28th Apr 2003 22:57
@Dark_Basic_Pro_Master: because users of dbp will want to use inkey$() for different uses (some people may want re-occurring text), repeat protection hasn't been written into the command.

I'm afraid you'll have to do some of these things manually, like the pros

PS - You are a master but don't know yhow to detect if a key is pressed?

You are the th person to view this signature.
Programmers don't die, they just Gosub without return....
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 29th Apr 2003 04:11 Edited at: 29th Apr 2003 04:14
also if you only want something done when the key is pressed try setting a flag to capture the key state. This snippet will only registar the 'A' key captial on not when the key is pressed the key is first pressed, to get it to registar again you must let off the 'a' key. With out a flag in it you going to have that key returned as pressed 30 time a second or whatever you sync rate is.
press the S key to see no key flag and see the difference

sync on
sync rate 30
Akeydownflag = 0
do
if keystate(30) = 1 and Akeydownflag = 0
Akeydownflag = 1
print "the A is key down"
endif
if keystate(30) = 0
Akeydownflag = 0
endif
if keystate(31) = 1 then print "the S key is down"
sync
loop


You really should change you nickname until you really are a master or very few here are going to take you seriously and offer any help on simple stuff like this.

CTP

Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 2nd May 2003 12:41
david wat u told is right, BUT THEY CAN SURELY SET ANOTHER COMMOND FOR THAT PURPOSE AND HAVE ONE WITH THE PROTECTION. This is really nonsense.

I am da man! Beware of my LAZER EYES!
Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 2nd May 2003 12:50


i used that code. I got this error "variable 'mus' does not exist at line 7"

so whats the big deal? i followed the manual and used that command. Any mistakes?

And yea also tell me if i used those key presses command properly.

I am da man! Beware of my LAZER EYES!
Danmatsuma
21
Years of Service
User Offline
Joined: 2nd Mar 2003
Location: Australia
Posted: 2nd May 2003 13:35
So many mistakes it's not funny, change your handle
look at the difference:


Also, the way you're doing that working you'll find that unless you tap the keys within one loop it will try to execute the commands until you let go, better to use a push on push off type solution.

Also, think about adding some messages to let the user (you) know what's happening within the program.

ZX Spectrum 48k Issue 3, Radio shack Tape drive, Rank arena 12" T.V. set.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd May 2003 15:21
Quote: "david wat u told is right, BUT THEY CAN SURELY SET ANOTHER COMMOND FOR THAT PURPOSE AND HAVE ONE WITH THE PROTECTION. This is really nonsense"


lol, you'll be saying next that they should put a command in that writes you game for you.

This is *programming* - the idea is that if the language doesn't provide exactly what you want, you can code it yourself.

Changed code, to stop the repeat:

Danmatsuma
21
Years of Service
User Offline
Joined: 2nd Mar 2003
Location: Australia
Posted: 2nd May 2003 15:24
*lol*, awww now you gone and done it all for 'im, at this rate he won't ever have to learn

ZX Spectrum 48k Issue 3, Radio shack Tape drive, Rank arena 12" T.V. set.
Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 2nd May 2003 19:42
Ianm, so, u said they don't give us wat we want. THE WHY THE HELL IS DBPRO SO COSTLY? in the site it says its very easy, and here, even making a small program is like catching star! If the program was free, i cannot say these thing, but people pay for this and this is wat they get? and other thing about teasing me, u better be careful next time!

I am da man! Beware of my LAZER EYES!
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 2nd May 2003 19:51
It easy compared to other languages, I love programming, so challenging (no matter the language) yet so fun.. you think DBP is hard and costly, well go try programming a game in VC++ see how hard it is then, even though DBP is still hard, it is a lot easier for game programming then a language like VC++, DBP is costly? Well Studio .net which has VC++ on it, costs:

Quote: "Visual Studio .NET Professional
(Full Packaged Product) $1,079 US "


I hear and I forget. I see and I remember. I do and I understand.
Richard Davey
Retired Moderator
22
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 2nd May 2003 19:53
We do give you the exact commands you need.

You just didn't understand why you needed to use them.

That is not a fault of DarkBASIC and no programming language on earth would make it any easier for you.

Listen to the very good advice that has been given to you in this thread if you wish to learn the right way to do it and to learn how to program.

Perhaps a "click and play" style program would be better for you to start with? Or certainly something like the Beginners Guide book which covers these very topics.

Cheers,

Rich

"Gentlemen, we are about to short-circuit the Universe!"
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 2nd May 2003 19:56
I agree wholly with what Rich has said, and the 750+ page book is excellent, I highly recommend it.

I hear and I forget. I see and I remember. I do and I understand.
Pal
21
Years of Service
User Offline
Joined: 13th Apr 2003
Location:
Posted: 2nd May 2003 20:42
ok. Thanks. I am just searching for a free tutorial instead of buying the beginners guide

I am da man! Beware of my LAZER EYES!
John H
Retired Moderator
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 4th May 2003 00:18
Why not just use the ones on the Dark Basic site? There is a post at the top of this forum about them.

RPGamer

Current Project: Eternal Destiny
Tech Demo - Colan Island: Currently 716 Lines
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 4th May 2003 16:44 Edited at: 4th May 2003 16:44
Yeah they're good, I loved the star field one, but the tutorials aren't structured in any fashion, well they are, but none of them follow on (well starfield1, starfield2 do, but you know what I mean) with a book at your fingertips instead of alt-tabbing (can make you lose your concentration) and going from start to finish in a structured manner.. I'm beginning to waffle, and it looks like I've been paid £££'s to advertise (I haven't), it's just that when I see posts like this, and I think if they had the book they wouldn't be asking them in this fashion.

P.S This is not a flame, and is not intended as 'flamebait'.

I hear and I forget. I see and I remember. I do and I understand.

Login to post a reply

Server time is: 2024-09-20 08:01:54
Your offset time is: 2024-09-20 08:01:54