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 / inkey problem

Author
Message
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 23rd Jan 2008 00:45 Edited at: 23rd Jan 2008 00:46
ok i'm making a 2 player game and decided player 2 is going to use the a and d keys i set the controls up it works fine except if player 2 is moving using a and d then player 1 pressed one of his arrow keys to move player 2 stops and the player 2 has to press a or d to move again both of the sprites can move at the same time heres the code for player 2


code for player 1



Windows Is better than everything
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Jan 2008 01:35
For controlling objects, it's best to avoid using inkey$(). inkey$() is good if you need to return a single character input from the keyboard (as it only reads one key at a time). You should use keystate() to check if a particular key is being pressed. The number that goes inside of keystate() is the scancode of the key you want to check. Just a note, avoid using scancode() as a control as well, you'll end up with similar results to inkey$(). Here's a little program that will easily allow you to check which scancodes belong to which keys on the keyboard. You can press a key and just write down the number you will use with keystate.



so for D, for example, instead of

if inkey$() = "d"

you'd use

if keystate(32)=1 then etc

Enjoy your day.
Mugen Wizardry
User Banned
Posted: 23rd Jan 2008 02:14 Edited at: 23rd Jan 2008 02:17
@Ed222: Hello, Ed222! =)

Now I am no expert at DBC because I do not have it, however, from what I've learned over the past few years, should help you out, if not alot, at least a bit =) (Experienced coders, correct my code if I am wrong in any way), but here is my shot at how you should use keystates:



EDIT: In the event that DBC does not let you use the "<>" not symbol, then just replace it with "=1" =)

I hope this helps you! =)

Good luck with your project! =)

~M.W~
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 23rd Jan 2008 03:51
Thank you both @ latch you code help me out but is there any way to make the text less blinky I tried sync on and sync it turns out that is makes the program lag badly my computer almost froze anyway to do this?

Windows Is better than everything
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 23rd Jan 2008 04:18
try adding sync and dropping the repeat loop:



Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Jan 2008 08:20
@Ed222

That little blurb was just a way to find the scancode numbers for different keys on the keyboard. You can get the same info from a chart. It was only meant as a quick reference then you can discard it. The focus is on the Keystate() which returns a 1 if a particular key is pressed or a zero if it isn't. Inside the () of keystate goes the scancode number of the key you want to check.

Quote: "any way to make the text less blinky I tried sync on and sync it turns out that is makes the program lag badly my computer almost froze anyway to do this?"


If you are just trying to manage the flickering of that snippet, Ortu's suggestion should work.

If you want to try and manage it the way I wrote the snippet, then the sync has to go inside the repeat loop because it will refresh the text as long as you have a key pressed - otherwise since sync is set to on, it's waiting to be told when to refresh and will lag:



I'm not quite sure why I have the two loops, I think I was planning on writing something more.

Enjoy your day.
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 23rd Jan 2008 20:16
thanks and i fixed the inkey with keystate

Windows Is better than everything

Login to post a reply

Server time is: 2025-06-02 09:42:15
Your offset time is: 2025-06-02 09:42:15