Author Topic: [Solved] Keybind Question [Thanks Destiny/Zack0Wack0 and Amade!]  (Read 705 times)

What is the if statement in a keybind for?
Code: [Select]
if(!$ClientKill::Binds) {
    $remapDivision[$remapCount] = "Client Kill Mod";
    $remapName[$remapCount] = "Self Delete";
    $remapCmd[$remapCount] = "loool";
    $remapCount++;
    $ClientKill::Binds=1;
}
« Last Edit: November 12, 2011, 06:30:37 AM by jes00 »

Its only purpose is to prevent the keybind from being registered twice if the script it's in were to be executed twice.

So if a keybind is calling a function when it is pushed and again when the key is released how would I make it toggle something only on release?

The function that gets called ("loool") gets passed a boolean, which will be true if the keybind was just pressed or false if it was just released.

Code: [Select]
function loool(%down)
{
if(!%down)
echo("Released");
else
echo("Pressed");
}

The function that gets called ("loool") gets passed a boolean, which will be true if the keybind was just pressed or false if it was just released.

Code: [Select]
function loool(%down)
{
if(!%down)
echo("Released");
else
echo("Pressed");
}
It says the bolded is a syntax error : /
Quote
function NightVisionToggle(%client)
{
   if(!%down)
      if($NightVision::isOn == 1)
      {
      NightVision.setVisible(0);
      $NightVision::isOn = 0;
      }

      else if($NightVision::isOn == 0)
      {
      NightVision.setVisible(1);
      $NightVision::isOn = 1;
      }
   else
      // echo("Pressed");
}

You need to put curly braces {} around conditionals (except if its only one line). Also, you've commented out the one line statement in the else and it's using the last } as the one line of code instead.
« Last Edit: November 11, 2011, 07:30:10 PM by Destiny/Zack0Wack0 »

You need to put curly braces {} around conditionals (except if its only one line). Also, you've commented out the online statement in the else and it's using the last } as the one line of code instead.
So this?
Code: [Select]
function NightVisionToggle(%client)
{
if(!%down)
{
if($NightVision::isOn == 1)
{
NightVision.setVisible(0);
$NightVision::isOn = 0;
}

else if($NightVision::isOn == 0)
{
NightVision.setVisible(1);
$NightVision::isOn = 1;
}
}
else
echo("Night vision toggled.");
}

You need to put curly braces {} around conditionals (except if its only one line). Also, you've commented out the online statement in the else and it's using the last } as the one line of code instead.
Basically you can't have else statements just floating there.

So this?
Code: [Select]
function NightVisionToggle(%client)
{
if(!%down)
{
if($NightVision::isOn == 1)
{
NightVision.setVisible(0);
$NightVision::isOn = 0;
}

else if($NightVision::isOn == 0)
{
NightVision.setVisible(1);
$NightVision::isOn = 1;
}
}
else
echo("Night vision toggled.");
}
%client shouldn't be there, it should be %down.

%client shouldn't be there, it should be %down.
It works, thanks!