Author Topic: Toggle  (Read 1105 times)

How do you make something toggleable?
Like something when you submit a command, it will say something, then when you do it again, it will say something else, then repeat?

try this
Code: [Select]
function ServerCmdtoggle(%client)
{
if($mode >= 1)
{
messageAll(",","mode is on");
}
if($mode <= 0)
{
messageAll(",","mode is off");
}
}

Or a more compressed format:
Code: [Select]
function toggle() {
$Toggle = !$Toggle;
if($toggle)
MessageAll('',"Toggle is on");
else
MessageAll('',"Toggle is off");
}
EDIT: Hal, you can use == or $= instead of >= and <=.
EDIT2: Hal, Your code doesn't even toggle, it just tells you if the command is activated or not.

Code: [Select]
switch($togglethingy)
{
   case true:
      $togglethingy = false;
      //do toggle off things here
   case false:
      $togglethingy = true;
      //do toggle on things here
}
...or for strings...
Code: [Select]
switch$($togglethingy)
{
   case "Off":
      $togglevar = false;
      //do toggle off things here
   case "On":
      $togglevar = true;
      //do toggle on things here
}

Code: [Select]
switch($togglethingy)
{
   case true:
      $togglethingy = false;
      //do toggle off things here
   case false:
      $togglethingy = true;
      //do toggle on things here
}
I think your definition is best. lol, thanks.
...or for strings...
Code: [Select]
switch$($togglethingy)
{
   case "Off":
      $togglevar = false;
      //do toggle off things here
   case "On":
      $togglevar = true;
      //do toggle on things here
}


Why are you using a switch for an either or test?  You really should just use if/else.