Game Development Community

Costum key mapping

by Rami Sleiman · in Torque Game Engine · 02/18/2010 (8:38 am) · 4 replies

I'm making a function where the player can define their own keys in my space shooter.

I'm using guitexteditctrl objects to get the key specified.

function darwinPlayer::changekeys()
{
//Don't know if this is needed
GlobalActionMap.unbind(keyboard, $up);
GlobalActionMap.unbind(keyboard, $down);
GlobalActionMap.unbind(keyboard, $left);
GlobalActionMap.unbind(keyboard, $right);
GlobalActionMap.unbind(keyboard, $fire);
GlobalActionMap.unbind(keyboard, $super1);
GlobalActionMap.unbind(keyboard, $super2);

$up = up.getText();
$down = down.getText();
$left = left.getText();
$right = right.getText();
$fire = fire.getText();
$super1 = super1.getText();
$super2 = super2.getText();

GlobalActionMap.bindCmd(keyboard, $up, "pDarwinUp();", "pDarwinUpStop();");
GlobalActionMap.bindCmd(keyboard, $down, "pDarwinDown();", "pDarwinDownStop();");
GlobalActionMap.bindCmd(keyboard, $left, "pDarwinLeft();", "pDarwinLeftStop();");
GlobalActionMap.bindCmd(keyboard, $right, "pDarwinRight();", "pDarwinRightStop();");
GlobalActionMap.bindCmd(keyboard, $fire, "darwinMissile::fire();", "darwinMissile::stopfire();");
GlobalActionMap.bindCmd(keyboard, $super1, "darwinSuper::createSuper();", "");
GlobalActionMap.bindCmd(keyboard, $super2, "finkar::doAttack();", "");

Restart::replay();
}


I have confirmed that you can use variables where you decide what key you should use.

I can't get it to work, all that happens is that I can't move my player or use any of my keys.

About the author

Recent Threads

  • GuiMLTextCtrl question

  • #1
    02/18/2010 (8:50 am)
    Maybe you just need to activate the action map using the push() method.
    #2
    02/18/2010 (8:56 am)
    I don't understand how that method works, would you fill me in?

    I added the line GlobalActionMap.push() but it does not seem to do anything.

    In my player onLevelLoaded function I define the keys like this:

    ///////

    GlobalActionMap.bindCmd(keyboard, $up, "pDarwinUp();", "pDarwinUpStop();");
    GlobalActionMap.bindCmd(keyboard, $down, "pDarwinDown();", "pDarwinDownStop();");
    GlobalActionMap.bindCmd(keyboard, $left, "pDarwinLeft();", "pDarwinLeftStop();");
    GlobalActionMap.bindCmd(keyboard, $right, "pDarwinRight();", "pDarwinRightStop();");
    GlobalActionMap.bindCmd(keyboard, $fire, "darwinMissile::fire();", "darwinMissile::stopfire();");
    GlobalActionMap.bindCmd(keyboard, $super1, "darwinSuper::createSuper();", "");
    GlobalActionMap.bindCmd(keyboard, "u", "togglescreen();", "");
    GlobalActionMap.bindCmd(keyboard, $super2, "finkar::doAttack();", "");
    /////
    #3
    02/19/2010 (8:57 am)
    Are there any errors in the console log? Try to use echo() to find out if your functions are called or where the flow of your code gets stuck.

    Here's some information about action maps that could help. you can search the forums for actionmap also.
    #4
    02/19/2010 (10:16 am)
    Get no error messages.

    I get values from the texteditctrl objects.

    I've tried to .pop() and after binding .push() does nto work.