Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (ozgur, degenerate_762, 7th_zorro), 1,075 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Key Mapping? #374842
06/21/11 22:32
06/21/11 22:32
Joined: Aug 2002
Posts: 164
Houston
Nicholas Offline OP
Member
Nicholas  Offline OP
Member

Joined: Aug 2002
Posts: 164
Houston
I am sure this has been done before, but I am looking for a refresher since I can't find any mention of it.
I am looking for a way to remap my keys with as little code as possible.
What's the best way to remap my keys/joystick buttons?
I was thinking of using strings so I could do something like:

STRING* jump = "joy_1";

if (jump ==1){player_jump;}

this would obviously try to use joy_1 as the jump button, but since I don't think I can use a string in an if statement I'm not sure of the best way to do it.
I would use a panel or ini file to remap the keys as need be, but don't want to have hundreds of if then statements inside of each other for each possible combination.
Any help would be great

thanks


Black holes are where God divided by zero.
Re: Key Mapping? [Re: Nicholas] #374843
06/21/11 22:50
06/21/11 22:50
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
you can't do that, try this:

Code:
#define jump joy_1

....

if (jump ==1){player_jump;}




3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: Key Mapping? [Re: painkiller] #374856
06/22/11 04:49
06/22/11 04:49
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
look up key_set in the manual.

Re: Key Mapping? [Re: lostclimate] #374932
06/22/11 15:25
06/22/11 15:25
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
Key_set will not help, as it is used to map on_key functions, and neither will a #define statement, as that doesn't even allow you to remap keys in game.

What you need to use is the key_for_str() and str_for_key() functions, but those only work for keyboard input. For mouse and joystick input, search for my functions on the forums: input_for_str() and str_for_input(). They work exactly the same as key_for_str() and str_for_key(), but they also accept mouse and joystick scan codes.


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Key Mapping? [Re: Redeemer] #374933
06/22/11 15:27
06/22/11 15:27
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
I included a template file for this in my RPG Template that you can take out of AUM100. Reads custom key setup from a .ini file laugh


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Key Mapping? [Re: Helghast] #374937
06/22/11 16:23
06/22/11 16:23
Joined: Aug 2002
Posts: 164
Houston
Nicholas Offline OP
Member
Nicholas  Offline OP
Member

Joined: Aug 2002
Posts: 164
Houston
I've been meaning to take a look at AUM100, nice setup there with the search functions and all the downloads.
I think I got it to work with keyboard and joysticks with as little code as possible. I needed to make it know if the button was held down so remapping the key to the function didn't seem to work too well, so I used a while loop in an action and just used the function part to set a var to the key pressed

var duck_v;
var jump_v;

function duck_f() {duck_v = key_lastpressed; } //set duck var
//joy_1 = 256, a = 30, etc
function jump_f() {jump_v = key_lastpressed; } //set jump var

//use this part for the mapping:

while (key_any == 0) { wait(1); } // wait until a key is hit
key_set(key_lastpressed,duck_f); // assign function to key
while (key_any == 1) { wait(1); } // wait until key is released
while (key_any == 0) { wait(1); } // wait until a key is hit
key_set(key_lastpressed,jump_f); // assign function to key


//put the rest in a while loop somewhere"

if (key_pressed(jump_v) == 1){//jump anim/etc
if (key_pressed(duck_v) == 1){//duck animation/action/sound etc...

will also know if key is held down and since key_pressed works with the 256+ numbers not just the lower ones it'll work with joysticks too.


There might be a more correct way, but this seems to work for me. I'll still take a look at the aum and see if there is anything that'll work for my application in there


Black holes are where God divided by zero.
Re: Key Mapping? [Re: Helghast] #374956
06/22/11 18:39
06/22/11 18:39
Joined: Aug 2002
Posts: 673
Las Cruces, NM
JimFox Offline
User
JimFox  Offline
User

Joined: Aug 2002
Posts: 673
Las Cruces, NM
I don't see AUM100 at the magazine site.
Am I missing something?


Jim
Re: Key Mapping? [Re: JimFox] #374957
06/22/11 18:42
06/22/11 18:42
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I guess yes? Cause I see it without any problems. About key mapping, see shooter templates.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Key Mapping? [Re: 3run] #375014
06/23/11 09:44
06/23/11 09:44
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
There is also custom key mapping in the Super Menu that I did a while ago for TerraSame. Works similar to what you posted above laugh


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1