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 / Wait for: Enter

Author
Message
RoyalBlood
15
Years of Service
User Offline
Joined: 8th Apr 2009
Location: Stuck in this box!
Posted: 12th Apr 2009 07:15
Sorry but, I'm kind of new:
What code would I put if I wanted my program to wait for a specific key, rather than just "wait key"?

Fear me, you really should...
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 12th Apr 2009 16:32 Edited at: 12th Apr 2009 16:32
You would need to use a loop.

I would suggest a WHILE ENDWHILE loop. Those work like this: While the condition next to the word WHILE is met, everything inbetween WHILE and ENDWHILE keeps happening over and over again. When the condition is no longer met, the program leaves that loop and goes on the the next line of code. (That next line of code is the line after the ENDWHILE command)

To detect if the ENTER key is being pressed, for example, you would use the Returnkey() command. Returnkey() spits out a number one if you press enter, and a 0 if you are not.

So, to put the two together, you would come out with something like this. The REM command is just to make comments about the code and are not actual commands.



Without my comments:


<---Spell casting battle game!
mike5424
15
Years of Service
User Offline
Joined: 30th Mar 2009
Location:
Posted: 12th Apr 2009 16:50 Edited at: 17th Apr 2009 14:25
ifkeystate(14)=1
the brackets are for the key number 14 is W

www.madninjas.co.nr we are mad and we are ninjas
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 16th Apr 2009 02:34
Quote: "the rackets are for the key number 14 is W"


No, 17 is W...

<---Spell casting battle game!
RoyalBlood
15
Years of Service
User Offline
Joined: 8th Apr 2009
Location: Stuck in this box!
Posted: 16th Apr 2009 02:58
^You're right...

AMPConcepts.webs.com
RoyalBlood
15
Years of Service
User Offline
Joined: 8th Apr 2009
Location: Stuck in this box!
Posted: 6th May 2009 02:16
Sorry to bring this back up guys, but whi is my code snippet not working?



AMPConcepts.webs.com
Herakles
15
Years of Service
User Offline
Joined: 6th Mar 2009
Location: Lost in my own head
Posted: 6th May 2009 02:31 Edited at: 6th May 2009 02:32
You need an ENDIF command and you need to put a space between the IF and the KEYSTATE. You also don't need the THEN. For example:



You could also use the SCANCODE command:



Swordfight! My cheesy little first game!
http://forum.thegamecreators.com/?m=forum_view&t=147808&b=36
RoyalBlood
15
Years of Service
User Offline
Joined: 8th Apr 2009
Location: Stuck in this box!
Posted: 6th May 2009 02:41
Oh, Thanks. I feel stupid for forgeting about endif...

AMPConcepts.webs.com
Herakles
15
Years of Service
User Offline
Joined: 6th Mar 2009
Location: Lost in my own head
Posted: 6th May 2009 02:59
Quote: "Oh, Thanks. I feel stupid for forgeting about endif"


It happens to everyone at some point or another.

Swordfight! My cheesy little first game!
http://forum.thegamecreators.com/?m=forum_view&t=147808&b=36
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th May 2009 08:16
Quote: "Oh, Thanks. I feel stupid for forgeting about endif..."


You shouldn't.



This should work just fine. Your issue was the space between if and keystate.
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 7th May 2009 00:40
As Kira said.

There are two types of IF statement.

Type 1, the one liner:


or Type 2, the multiple liner:


There is also the ELSE command, which is useful in Type 2 IF statements, though unfortunately DarkBasic Pro is missing an ELSEIF command, so you end up with something structured like this:


"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Herakles
15
Years of Service
User Offline
Joined: 6th Mar 2009
Location: Lost in my own head
Posted: 7th May 2009 02:55 Edited at: 7th May 2009 03:01
> Dream and Death

You could do else;if like this:



EDIT: I don't know why I typed all that out myself instead of just copying your code and changing what I had too to demonstrate what I was saying. I'm crazy.

Swordfight! My cheesy little first game!
http://forum.thegamecreators.com/?m=forum_view&t=147808&b=36
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 8th May 2009 00:12
Err, Herakles that is the same as my code - all you've done is changed the formatting!

A true ELSEIF would allow you to build a compound if statement without having multiple ENDIFs at the end. Our example here only has two, but when you start to nest five or six IF...ELSE...ENDIF statements, having five or six ENDIFs at the end is just silly!

At least with vb, for example, you can have:


"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 8th May 2009 09:02
yes, but that is what we have CASE SELECT for, it works just like an elseif... i think...

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 8th May 2009 21:07
A SELECT statement only allows you to select a CASE based on the value of one variable - it doesn't deal with complex cases,

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Herakles
15
Years of Service
User Offline
Joined: 6th Mar 2009
Location: Lost in my own head
Posted: 9th May 2009 03:27 Edited at: 9th May 2009 03:29
Quote: "Err, Herakles that is the same as my code - all you've done is changed the formatting!"


I was just using it as an example of how you could use this thing: ";" to squish the ELSE and IF commands together to save a line. I just typed pretty much the same thing out myself (which was a stupid and unnecessary thing to do, I know) so it's in my personal coding format, but it should do the same thing as your code (which was intentional). "ELSEIF" isn't really necessary because you can just do IF statements within IF statements. Yeah, it'd be better to have ELSEIF 'cause you wouldn't need to waste as many lines with ENDIFs, but it's not a major loss for the language.

Swordfight! My cheesy little first game!
http://forum.thegamecreators.com/?m=forum_view&t=147808&b=36

Login to post a reply

Server time is: 2024-11-24 08:16:53
Your offset time is: 2024-11-24 08:16:53