Author Topic: Torque fails to do math. [Solved]  (Read 1006 times)

Okay, so I'm running a loop using schedules to figure out when the daycycle repeats itself, but once the daycycle is set over 1000 seconds long, Torque fails to do math, and just runs the schedule as if it's an infinite loop.
Current code:

function getDayTime()
{
   %time = $Sim.Time / DayCycle.dayLength + DayCycle.dayOffset;
   $DayTime = (%time - mFloor(%time)) *1000;
   return $DayTime;
}

new ScriptObject(day_cycle);

day_cycle.Days = "1";
day_cycle.Months = "1";
day_cycle.Years = "1";



function dayCycleAnnouncementLoop()
{
   day_cycle.Days++;
   if(day_cycle.Days >= 31)
   {
      day_cycle.Days = 1;
      day_cycle.Months++;
   }
   if(day_cycle.Months >= 12)
   {
      day_cycle.Months = 1;
      day_cycle.Years++;
   }
   messageAll('', "\c6It is now \c3" SPC day_cycle.Months @ "/" @ day_cycle.Days @ "/" @ day_cycle.Years);
   dayCycle.announcementSchedule = schedule(dayCycle.dayLength *1000, 0, dayCycleAnnouncementLoop);
}

function serverCmdtoggleDayCycleAnn(%c)
{
   if(isEventPending(dayCycle.announcementSchedule))
   {
      cancel(dayCycle.announcementSchedule);
      messageAll('', "\c3" @ %c.getPlayerName() SPC "\c6has \c0 disabled \c6day cycle announcements.");
   }
   else
   {
      dayCycleAnnouncementLoop();
      messageAll('', "\c3" @ %c.getPlayerName() SPC "\c6has \c2enabled \c6day cycle announcements.");
   }
}

EDIT: Apparently, schedules break when you go over anything above 999*1000.
« Last Edit: August 01, 2014, 11:44:57 AM by Cruxeis »

EDIT: Apparently, schedules break when you go over anything above 999*1000.
Torque uses scientific notation for numbers above 1 million.
1000*1000 becomes 1e+006, which the default math library can't perform math on because it's now a string instead of a numeric value.
Either look into one of the string math libraries people have made, or, since multiplying by a positive power of ten just adds zeroes, replace dayLength * 1000 with dayLength @ "000"
« Last Edit: August 01, 2014, 11:35:24 AM by Headcrab Zombie »

Torque uses scientific notation for numbers above 1 million.
1000*1000 becomes 1e+006, which the default math library can't perform math on because it's now a string instead of a numeric value.
Either look into one of the string math libraries people have made, or, since multiplying by a positive power of ten just adds zeroes, replace dayLength * 1000 with dayLength @ "000"
Hooray for Torque. Anyways, thanks!

Hooray for Torque. Anyways, thanks!
You can also use (%a * %b) | 0 to force the result as a 32-bit signed integer, which will work with schedules and work up to around 2 billion ms (Just under 25 days), and does not require any string manipulation or math libraries.