Game Development Community

Button1 && button0

by Tim Tebow · in Torque Developer Network · 04/23/2007 (10:48 am) · 4 replies

Im trying to get it so I can move my character by holding down both mouse buttons at the same time. Ive tried about 4 or 5 diffrent variations of code but either it wont work or will work with one button or the other. Im looking in my default.bind file for the tutorial.base game start...

any poitners on what to do? or even a keyword to use in the TDN ive tried looking up mouse commands , button commands, binds and everything dealing with the keyboard and mouse binds deals with 1 key at a time even if i do "button1 button2" it will work if i just hold down button1....

Thanks for any help!

#1
04/23/2007 (11:15 am)
This is just "shooting from the hip," but have you tried this approach:

$leftMouseIsDown = 0;
$rightMouseIsDown = 0;

function rightClick(%val)
{
    if(%val)
    {
           $rightMouseIsDown = 1;

           if($leftMouseIsDown && $rightMouseIsDown)
                  moveForward(%val);
    }
    else
        $rightMouseIsDown = 0;
}
function leftClick(%val)
{
    if(%val)
    {
           $leftMouseIsDown = 1;
           
           if($leftMouseIsDown && $rightMouseIsDown)
                  moveForward(%val);
    }
    else
        $leftMouseIsDown = 0;
}
#2
04/23/2007 (2:55 pm)
I had to do some modification because of this piece of code

//moveMap.bind( mouse, button0, mouseTrigger );

if thats uncommented it wont work no matter what. Im not worried about that function right now but now I have to figure out how to get it to stop when I let go of the mouse buttons it just keeps running im going to try to find a function for something like mouseup and mousedown.

Thanks for the advice / help though Michael!
#3
04/23/2007 (3:49 pm)
The %val that gets passed into the function is what determines if a button is released. It's a 1 if the button was pressed, and 0 if the button was released.
#4
04/23/2007 (5:38 pm)
Here is my code still cant get it ive tried redoing the whole thing with same results. it dont register the release of the mouse buttons

//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------


//------------------------------------------------------------------------------
// Key bindings for the in-game action Map
//------------------------------------------------------------------------------

if ( isObject( moveMap ) )
   moveMap.delete();
new ActionMap(moveMap);

//------------------------------------------------------------------------------
// Misc. in-game keys

function escapeFromGame()
{
   if ( $Server::ServerType $= "SinglePlayer" )
      MessageBoxYesNo( "Quit Mission", "Exit from this Mission?", "disconnect();", "");
   else
      MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
}

moveMap.bindCmd(keyboard, "escape", "", "escapeFromGame();");


//------------------------------------------------------------------------------
// Movement Keys

$movementSpeed = 1; // m/s

$leftMouseIsDown = 0;
$rightMouseIsDown = 0;

function rightClick(%val)
{
    if(%val)
    {
           $rightMouseIsDown = 1;

           if($leftMouseIsDown && $rightMouseIsDown)
                  $mvForwardAction = %val * $movementSpeed;
    }
    else
    {
        $rightMouseIsDown = 0;
    }
}
function leftClick(%val)
{
    if(%val)
    {
           $leftMouseIsDown = 1;
           
           if($leftMouseIsDown && $rightMouseIsDown)
                  $mvForwardAction = %val * $movementSpeed;
    }
    else
        $leftMouseIsDown = 0;
}




function setSpeed(%speed)
{
   if(%speed)
      $movementSpeed = %speed;
}

function moveleft(%val)
{
   $mvLeftAction = %val * $movementSpeed;
}

function moveright(%val)
{
   $mvRightAction = %val * $movementSpeed;
}

function moveforward(%val)
{
   $mvForwardAction = %val * $movementSpeed;
}

function movebackward(%val)
{
   $mvBackwardAction = %val * $movementSpeed;
}

function moveup(%val)
{
   $mvUpAction = %val * $movementSpeed;
}

function movedown(%val)
{
   $mvDownAction = %val * $movementSpeed;
}

function turnLeft( %val )
{
   $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function turnRight( %val )
{
   $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function panUp( %val )
{
   $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function panDown( %val )
{
   $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function getMouseAdjustAmount(%val)
{
   // based on a default camera fov of 90'
   return(%val * ($cameraFov / 90) * 0.01);
}

function yaw(%val)
{
   $mvYaw += getMouseAdjustAmount(%val);
}

function pitch(%val)
{
   $mvPitch += getMouseAdjustAmount(%val);
}

function jump(%val)
{
   $mvTriggerCount2++;
}

function mouseTrigger(%val)
{
  $mvTriggerCount0++;
}

moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
moveMap.bind( keyboard, w, moveforward );
moveMap.bind( keyboard, s, movebackward );
moveMap.bind( keyboard, space, jump );
movemap.bind(mouse, button0, leftclick)
movemap.bind(mouse, button1, rightclick)
moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );
//moveMap.bind( mouse, button0, mouseTrigger );


//------------------------------------------------------------------------------
// Camera & View functions

function toggleFreeLook( %val )
{
   if ( %val )
      $mvFreeLook = true;
   else
      $mvFreeLook = false;
}

$firstPerson = true;
function toggleFirstPerson(%val)
{
   if (%val)
   {
      $firstPerson = !$firstPerson;
      ServerConnection.setFirstPerson($firstPerson);
   }
}

function toggleCamera(%val)
{
   if (%val)
      commandToServer('ToggleCamera');
}

moveMap.bind( keyboard, z, toggleFreeLook );
moveMap.bind(keyboard, tab, toggleFirstPerson );
moveMap.bind(keyboard, "alt c", toggleCamera);


//------------------------------------------------------------------------------
// Helper functions used by the mission editor

function dropCameraAtPlayer(%val)
{
   if (%val)
      commandToServer('dropCameraAtPlayer');
}

function dropPlayerAtCamera(%val)
{
   if (%val)
      commandToServer('DropPlayerAtCamera');
}

moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
moveMap.bind(keyboard, "F7", dropPlayerAtCamera);


//------------------------------------------------------------------------------
// Key bindings for the Global action map available everywhere
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Misc.

GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");


//------------------------------------------------------------------------------
// Dubuging Functions

$MFDebugRenderMode = 0;
function cycleDebugRenderMode(%val)
{
   if (!%val)
      return;

   if (getBuildString() $= "Debug")
   {
      if($MFDebugRenderMode == 0)
      {
         // Outline mode, including fonts so no stats
         $MFDebugRenderMode = 1;
         GLEnableOutline(true);
      }
      else if ($MFDebugRenderMode == 1)
      {
         // Interior debug mode
         $MFDebugRenderMode = 2;
         GLEnableOutline(false);
         setInteriorRenderMode(7);
         showInterior();
      }
      else if ($MFDebugRenderMode == 2)
      {
         // Back to normal
         $MFDebugRenderMode = 0;
         setInteriorRenderMode(0);
         GLEnableOutline(false);
         show();
      }
   }
   else
   {
      echo("Debug render modes only available when running a Debug build.");
   }
}

GlobalActionMap.bind(keyboard, "F9", cycleDebugRenderMode);

Does anything look wrong?