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 / question regarding keystate

Author
Message
strykerm
14
Years of Service
User Offline
Joined: 25th Aug 2010
Location:
Posted: 13th Dec 2011 23:41 Edited at: 17th Dec 2011 19:25
Hi ya'll. I'm having some trouble with the keystate command. I know the number of the keys I'm checking to see whether are being pressed or not. Here's the problem. I've got a 2d bitmap, and a sprite that
moves along a X axis. When it crosses infront of a door, I've got
the name of the door assigned to a variable (PlayerLoc$). When the sprite is infront of the door, I want to be able to use the space bar, enter key or return key to open the door. Here's the code I've been using:

when ran, the enter key (number pad) works as it should, but the space bar and the enter key near the letters only goes to "Operations". In every one of the subroutines I've got the gosub main statement at the end to bring the program back to where the sprite and bitmap are first displayed. I tried using the 'return' statement instead, but it didn't make any difference. I can remove the 2nd and 3rd keystate parts and make it work with only one keystroke, if I have to, but I was wondering if there's any alternatives to doing that?
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 14th Dec 2011 02:56 Edited at: 14th Dec 2011 03:23
you have an issue with your conditionals:

the location is only linking with the numpad enter and so that is why that key works. or's break up and's try writing it thus:



or nested as:



this logic error can be seen in a small test snippet using your original structure:



also, unless this code is itself within a sub, you can remove the returns after the gosub call

if PlayerLoc$ = "Operations" then gosub Operations : return -> if PlayerLoc$ = "Operations" then gosub Operations


strykerm
14
Years of Service
User Offline
Joined: 25th Aug 2010
Location:
Posted: 14th Dec 2011 11:30
Thanks it works exactly like I need it to.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 14th Dec 2011 21:18
Hi, strykerm, this is kinda off-topic, but I'm suggesting it before you get a slap on the wrists from a mod. You really, really should place your code in "Code Snippets" (like the ones Ortu used). You can do this like so...

Your post, etc.
[ code]
Your code goes here.
[ /code]

...without the spaces between "[" and "code" & "/code". You'll notice a "code" button above the smileys. You can use this too if you wish. Also, you should be able to edit your posts by clicking "edit post".

strykerm
14
Years of Service
User Offline
Joined: 25th Aug 2010
Location:
Posted: 17th Dec 2011 01:59
thanks, I edited my post, and will keep that in mind in the future
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Dec 2011 19:26
I've just fixed your code tags for you - nonZero said without spaces: [[/b]code][/[b]code]

Login to post a reply

Server time is: 2024-11-22 10:55:18
Your offset time is: 2024-11-22 10:55:18