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 / holding 2 keys at once problem...

Author
Message
Gamers corner
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: USA
Posted: 17th Aug 2006 01:17
Im making a FPS and im trying to make it so you can use w,a,s, and d to move around, but just like in the tutorial "Free Flight", it stops saying that the button is pressed when you press another or move the mouse.

I know why this happens but is there a way you can move your FPS guy and turn the mouse without him stopping?

Gamerscorner

www.freewebs.com/monkeyproduction
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Aug 2006 03:17
Hello,

Instead of having the character react directly to a key press, set a variable to a value when the key press occurs. Have the character react to the value of the variable. You can then control the variable with different values to have various things occur.

When the cycle is complete, reset your variable to 0 or whatever and then have a variable set by the next keypress or mouse move.



Enjoy your day.
Gamers corner
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: USA
Posted: 17th Aug 2006 03:36
It still didnt work. it did the same thing as last time, and i tried it with WHILE.

remember im using inkey$()

www.freewebs.com/monkeyproduction
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 17th Aug 2006 13:53
use the keystate function

Return Value = keystate(scancode value of key to check)

returns 1 if the checked key is being pressed, otherwise zero is returned... Using inkey$ means every time you press a new key, the old keypress is lost
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 18th Aug 2006 15:20
hey Gamers Corner,

If your using the inkey$() comand (which is what i normally have), create a few variables like Up,Down,Left,Right, then when a key is pressed, check to see if the variables = 1, and respond that way.

A short code snippet would be something like this (written off the top of me head)



hopefully that should work, if not then my bad , tho it is a basic way of doing it. Tho the last couple of lines may be i nthe wrong place
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Aug 2006 19:49 Edited at: 18th Aug 2006 20:01
Bad idea!

What if he wanted to go up and left simultaneously? With that code it is not possible. As SimSmall said ... use keystate.

Here is some code to demonstrate how to use keystate. Use W,A,S,D to move the sprite around.



... and here is a list of scancode numbers to use with the keystate command:





Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 19th Aug 2006 03:05
hehe, my bad, my movement is on cursor keys, which my way would work for. (swapping inkey for upkey of corse)

Login to post a reply

Server time is: 2025-05-25 06:13:30
Your offset time is: 2025-05-25 06:13:30