Game Development Community

Timer issues

by Foestar · in Torque Game Engine Advanced · 03/20/2010 (10:09 pm) · 2 replies

Okay, so here is my code.
function singleplayerstart()
{
   $MMMP=1;
   Canvas.setCursor("DefaultCursor");
   createServer( "SinglePlayer", expandFileName("~/data/missions/Owlpoint.mis") );
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs($pref::Player::Name);
   %conn.setJoinPassword($Client::Password);
   %conn.connectLocal();

   if($daynighttimer==""){
      $daynighttimer=0;
   }

   if($time==""){
      $time="day";
      WorldTimer(0);
   }

}

function WorldTimer(%time) {
   schedule(1000, 0, DayNightTick, %time);
}
function DayNightTick(%time) {
   echo("timer tick");
   echo($time);
   echo($daynighttimer);
   $daynighttimer++;
   %time++;
   schedule(1000, 0, DayNightTick, %time);

   if($daynighttimer==16){
      if($time=="day"){
         $time="night";
         echo("It's day time");
         $daynighttimer=1;
      }
      if($time=="night"){
         $time="day";
         echo("It's night time");
         $daynighttimer=1;
      }
   }

}
Maybe I'm half asleep and missing something completely obvious..... which is probably the case. But for some reason when I'm watching the console it ticks until 15 and then echos saying it's day time and it's night time after. Every tick after that point states $time as day. Blah, someone mind pointing out my error.

#1
03/21/2010 (4:05 am)
the string compare operators are $= (equal) , !$= (not equal)
you're using the numeric operators instead
#2
03/21/2010 (8:36 am)
Doh!! Lol thanks Ivan.