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 / Why doesn't inkey$() work for player 2?

Author
Message
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 21st Jun 2009 23:45
Okay for some weird reason, when I try to activate one of player two's weapon, which is activated using the 8 button it will not show the sprite that I want it to but if I set it to a command such as end it works perfectly. I have edited my code to make it easier to show what I am focusing on so don't say some variables are not defined.



Please explain to why the inkey$() (8) does not work correctly?

Thanks,
Zeus
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd Jun 2009 00:54
inkey$() only returns the last pressed key, so if multiple keys are pressed it wont work, try using keystate() instead, it checks if the key you specify is pressed and returns a flag value so it works betr wen you need to check many keys

There are only 10 kinds of people in the world, those who understand binary and those who dont
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 22nd Jun 2009 01:19
Ahh man, now I have to learn my scancodes! Oh well, thanks!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 22nd Jun 2009 01:22
not that hard, just run this:



There are only 10 kinds of people in the world, those who understand binary and those who dont
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 22nd Jun 2009 01:29
Haha I beat you to it! Alright, thanks a lot though!
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Jun 2009 02:38
I don't want to post it too much as a direct picture in the forums so here's a link to my keystate graphic. It shows all the numbers you need under each key.

http://mysite.verizon.net/grueslayer/Keystate.png

Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 23rd Jun 2009 01:44
Scancode() doesn't work either. Here is the code I am trying to execute.



It says unrecognized parameter. What am I doing wrong now?
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jun 2009 01:47
because scancode() returns the scan value of the key you're pressing, what you want is:

keystate(scancode#)

where scancode# is the code of the key you're checking

There are only 10 kinds of people in the world, those who understand binary and those who dont
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 23rd Jun 2009 01:53
I am so sorry about the trouble. I have never worked with that command. Thank you!
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jun 2009 02:14
no prob, thats why this forum exists, just remember the functions of these commands:

inkey$() returns the STRING of the currently pressed key

scancode() returns the VALUE of the currently pressed key

keystate(scancode) returns the FLAG (0/1) of the specifyed key

There are only 10 kinds of people in the world, those who understand binary and those who dont
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 23rd Jun 2009 02:25
Got it. Thanks.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Jun 2009 02:25
@Zeus

Don't put a number inside scancode().

This is incorrect: scancode(inkey$() ) and so is scancode(2)

instead of

try


See the difference?

Enjoy your day.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jun 2009 04:12
.........did you not read my posts or something latch?

There are only 10 kinds of people in the world, those who understand binary and those who dont
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 23rd Jun 2009 04:14
Lol. Skiped right over it.

LOL!

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 23rd Jun 2009 04:23
Quote: ".........did you not read my posts or something latch?
"


Lol.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Jun 2009 05:21
Quote: ".........did you not read my posts or something latch"
?

Quote from That1SmartGuy

Quote: "not that hard, just run this:

+ Code Snippet

sync on : hide mouse

do
print scancode(inkey$() )
sync
cls
loop"


Perhaps you aren't reading your own posts.

Enjoy your day.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 23rd Jun 2009 05:27
sorry when I was typing that I guess I was thinking scancode() accepted a string paramter and outputted a scancode, good spot latch

There are only 10 kinds of people in the world, those who understand binary and those who dont
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 23rd Jun 2009 05:28
Quote: "
Perhaps you aren't reading your own posts."


LOL!


Well, the problem is fixed now guys, nothing to worry about. I appreciate all of your help just the same.

Login to post a reply

Server time is: 2024-05-20 12:50:45
Your offset time is: 2024-05-20 12:50:45