|
Easy keymapping
#188067
03/12/08 09:06
03/12/08 09:06
|
Joined: Apr 2005
Posts: 3,815 Finland
Inestical
OP
Rabbit Developer
|
OP
Rabbit Developer
Joined: Apr 2005
Posts: 3,815
Finland
|
People nowdays need to be able to modify the key mapping, so using key_w, key_s, etc. will not be tolerated. That's why one should use strings or other method for checking which key was pressed. No credits required, but note that this was also partially Kiyaku's idea. For this I made this simple script: Code:
// Key mapping string keyForward = "w"; string keyBackward = "s"; string keyStrafeLeft = "a"; string keyStrafeRight = "d"; string keyRun = "shiftl"; string keyJump = "space"; string keyStrafe = "ctrll";
function getKey(key) { return (key_pressed(key_for_str(key))); }
usage Code:
if(getKey(keyForward)) { //Do Stuff } // returns true/1/on wether button associated to forward movement is pressed
Key mapping can be found in the manual. Look for function "key_for_str" for complete list of accepted strings. AFAIK it's just key_blaa without the "key_". Edit: This should work on mouse, but I'm not completely sure.
"Yesterday was once today's tomorrow."
|
|
|
Re: Easy keymapping
[Re: Scorpion]
#188071
03/14/08 12:16
03/14/08 12:16
|
Joined: Apr 2005
Posts: 3,815 Finland
Inestical
OP
Rabbit Developer
|
OP
Rabbit Developer
Joined: Apr 2005
Posts: 3,815
Finland
|
Using defines won't allow you to change the keymapping without restart (same as using key_lol), so using strings, maybe in an array, is way better. Also you can use the strings themselves for display, and not to rewrite them. well, I use this to set the new key Code:
function setKey() { return (str_for_key(key_lastpressed)); }
Usage: Code:
... if(forwardchange == 1) { keyForward = setKey(); } ...
"Yesterday was once today's tomorrow."
|
|
|
Re: Easy keymapping
[Re: Inestical]
#188072
03/14/08 14:27
03/14/08 14:27
|
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B
Expert
|
Expert
Joined: Feb 2006
Posts: 2,185
|
Xarthor this is pretty good, i assume this is from my post about how to do this. I didn't think of doing it this way, but the problem is that str_for_key doesn't support mouse functions it's keyboard exclusive. i will be starting on one that will support mouse and joystick all in one, but it will take some time because i have to use the key numbers and then tell it to convert it to the key name "ie 1 = esc". thanks for the keyboard controls this would be very helpful for a puzzle game or any game that requires keyboard
- aka Manslayer101
|
|
|
Re: Easy keymapping
[Re: mpdeveloper_B]
#188073
03/14/08 16:17
03/14/08 16:17
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
@Inestical: You are right, you could use the text array for displaying the key mapping aswell. But (now here comes the but ) in my humble oppinion the normal/standard user might be confused by the names. Thus I did take my time to write some kind of hugh text array ranging to the highest scan code. It includes a name for the keys (that I can change etc.) but maintains the right order. Thus it allows me to access this text array with the scan code of the key and I'll be able to get the string I chosed for that specific key. just an idea
|
|
|
Re: Easy keymapping
[Re: Xarthor]
#188074
03/14/08 16:53
03/14/08 16:53
|
Joined: Feb 2008
Posts: 4 Nanning,Guangxi,China
harrisyu
Guest
|
Guest
Joined: Feb 2008
Posts: 4
Nanning,Guangxi,China
|
I think using number instead of string would be nicer. Because string comparing take times.
Here is what I though about customize control in game:
A function for returning string with given input,like: PlayerMoveForwardKey = getContStr( theControlNumberOfInput ); That's just for displaying what input have set for a certain action;
Then we store 'theControlNumberOfInput' in a value , use this value in the function that handling control reaction.
3D Game Studio commercial 7.07
Tools:Blender/Silo/Bryce/Photoshop/Artrage/Flash
I like platform game.
|
|
|
|