Author Topic: Syntax Error With Countdown  (Read 1606 times)

Hello. I'm working on a project. I'm new to scripting but I'm sure I'll get better as I go along. Here is my current script I'm working on.
Quote
function serverCmdStartAnni(%client)
{
    if(%client.isAdmin)
    {
       %count = ClientGroup.getCount();
          for(%cl = 0; %cl < %count; %cl++)
          {
             %clientB = ClientGroup.getObject(%cl);
             %clientB.centerPrint("<font:impact:50><color:f420eb>Annihilation round begins in 30 seconds! Prepare yourself!",5);
            %clientB.centerPrint(%timer,25);
          }
      %time = 30
      serTimer();
    }

    else
    {
   messageClient(%client, '', '\c6Only Admins can Start Annihilation!');
    }
}

function serTimer(%time);
{
   if (%time <= 0)
   {
      %count = ClientGroup.getCount();
          for(%cl = 0; %cl < %count; %cl++)
          {
             %clientB = ClientGroup.getObject(%cl);
             %clientB.centerPrint("<font:impact:50><color:f420eb>This Annihilation round has begun!",5);
          }
   }
   else
   {
      %time--;
   
      $ShutdownSchedule = schedule(1000, 0, "Timer", %time);
   }
}
The bold is where it said the error is at. I'm not really even sure how to program a countdown timer anyways. I'm really new to scripting and I'm sure I'll get better. The problems just make me be able to code better in the end.

I see I forgot a var change at the bottom as I was going off a shutdown script. I can't modify my op...

For the record, these kinds of things go in the Coding Help section.

when you get an error, check the line it highlights and before it
in this case, the  line above is missing a semicolon

For the record, these kinds of things go in the Coding Help section.
Ah, I did not even see that section when I posted this, sorry.

Ok, no more syntax errors, but now I when I type in /startanni, no text shows up. Does executing the other function cancel out my center prints?

New Code:
Quote
function serverCmdStartAnni(%client)
{
    if(%client.isAdmin)
    {
       %count = ClientGroup.getCount();
          for(%cl = 0; %cl < %count; %cl++)
          {
             %clientB = ClientGroup.getObject(%cl);
             %clientB.centerPrint("<font:impact:50><color:f420eb>Annihilation round begins in 30 seconds! Prepare yourself!",5);
            %clientB.centerPrint(%timer,25);
          }
      %time = 30;
      serTimer(%time);
    }

    else
    {
   messageClient(%client, '', '\c6Only Admins can Start Annihilation!');
    }
}

function serTimer(%time)
{
   if (%time <= 0)
   {
      %count = ClientGroup.getCount();
          for(%cl = 0; %cl < %count; %cl++)
          {
             %clientB = ClientGroup.getObject(%cl);
             %clientB.centerPrint("<font:impact:50><color:f420eb>This Annihilation round has begun!",5);
          }
   }
   else
   {
      %time--;
   
      $ShutdownSchedule = schedule(1000, 0, "Timer", %time);
   }
}

I recommend going to Coding Help for more info.

%clientB.centerPrint("<font:impact:50><color:f420eb>Annihilation round begins in 30 seconds! Prepare yourself!",5);
%clientB.centerPrint(%timer,25);

it looks like you print the first line, then instantly print out a blank line after (%timer is not defined -> ""?)
so the first function serverCmdStartAnni(%client) doesn't actually do too much with the centerprint besides clearing it, try eventing a centerprint to show for a while, typing this, and seeing if the evented one disappears

serTimer should print out stuff though

forgot to add, only if you get serTimer to be called with 0 or less, I don't think you have it looping
your $ShutdownSchedule = schedule(1000, 0, "Timer", %time); should probably be $ShutdownSchedule = schedule(1000, 0, "serTimer", %time);

Fixed It. Thanks for all your help. Locking.