A clock.

Author Topic: A clock.  (Read 3017 times)

I'm just looking for a code that will add a day every so many seconds/minutes/hours. That's really it.
I've jumped from CityRPG codes to little documentation things but I haven't found it, and I'm sure it's simple (And I could just be blind). If anyone could drop it here that'd be nice.

$day = 0;
$dayInterval = 300000;

function dayAdder()
{
     cancel($dayAdder);
     $day += 1;
     schedule($dayInterval, 0, dayAdder);
}

This adds 1 to the global variable $day every 5 minutes.

Thanks.
Uh, any idea why blockland keeps reading this as a syntax error?

$1 = "January";

I'm just naming a variable (I think?), like $day and other.

Uh I don't think variables can have number names

Uh I don't think variables can have number names

Indeed. Just to be precise, variable names cannot start with a number but anything else is fine.

$1 would be wrong but $month1 would be right. $1month is also incorrect.
« Last Edit: December 11, 2017, 07:07:56 AM by Marios »

Alright, well, with that fixed, why the heck is blockland registering THIS as an error? It's no different from any of the other Ifs I put.



(marked where it errors with ##)

Alright, well, with that fixed, why the heck is blockland registering THIS as an error? It's no different from any of the other Ifs I put.



(marked where it errors with ##)
you got a missing ; on the line above the ## error. generally you gotta look at the line before the error locator.

For what you appear to be doing, I would recommend using switch$ ($month) instead; nothing is wrong with what you have but it'll be more condensed - see below (note default for when none of the cases apply):

Code: [Select]
switch$ ($month)
{
     case 1:
          $m = "January";
     case 2:
          $m = "February";
     default:
          $m = "n/a"
}


thank you all.

edit
tried using Case so that individual months could have different day limits but it registered as a syntax error in the highlighted area. Dunno if its telling me switch is written wrong or case


« Last Edit: December 10, 2017, 07:23:18 PM by Doctor Disco »

You forgot the : after case and you can't nest ifs or loops into case results


Also what you're doing is stupid. Just increment days, write a function that divides the days by 31 and prints out a month. Having a day counter and a month counter is excessive, it's better to stick with a day counter and just make a basic return function that prints out a month.

If this is too complex, here's a tip: don't use a month variable- just use a day variable, divide by 31 and round down using mFloor(); and use the number you get to return a month

Example:

Code: [Select]
Function dayToMonth(%day)
{
     %val = mFloor(%day/31);
     Switch(%val)
     {
          Case 0:
               Return "January";
          Case 1:
               Return "Febuary";
           Default:
               Return "Nan";
        }
}
Then if you do echo(daytomonth(32)); you'll get Febuary, etc. to get the exact day of the month, use modulus % or subtract month*day from the total daycount
« Last Edit: December 10, 2017, 08:12:22 PM by PhantOS »

you’re gonna get wrong values on day 31+30, and it only gets worse from there. phantos pls

better is to hardcode array that states whats the max day of a month. i’ll expand this post later

For an rpg server where days go by every minute, that level of accuracy isn't necessary. Using 30 days per month for every month is like super easy and nobody notices the difference