$pingLoop = !$pingLoop;
if($pingLoop)
pingLoop();
else
cancel($pingLoopSched);
You could take this part further and change it to this
if(!$PingLoopBind)
{
$RemapDivision[$RemapCount] = "Ping";
$RemapName[$RemapCount] = "Toggle";
$RemapCmd[$RemapCount] = "togglePingLoop";
$RemapCount++;
$PingLoopBind = 1;
}
function togglePingLoop(%b)
{
if(!%b)
return;
if(isEventPending($PingLoopSched))
cancel($PingLoopSched);
else
pingLoop();
}
function pingLoop()
{
clientCmdBottomPrint("\c6Ping:" SPC serverConnection.getPing(), 1, 1);
$PingLoopSched = schedule(50, 0, pingLoop);
}schedule returns an index that can be used to cancel a schedule or see if it is still running, using
isEventPending. You can shorten this toggle function, if your ping loop is running then cancel it, if it isn't then start it. Now you need only one global variable for the loop, holding your schedule index.
You also don't have to clear the bottom print when canceling it as you already set it to disappear after 1 second.