Author Topic: Real life time synchronized daycycle (Updated again, v1.3)  (Read 6881 times)

This script finds your real time and syncs it with the daycycle. The daycycle will run for 24 hours and then restart.
Non-dedicated Server Usage: /synctime
Dedicated Server Usage: /synctime hour (uses 24 hour time format: http://www.onlineconversion.com/date_12-24_hour.htm )
Example for dedicated edition: /synctime 16
In layman's terms: If it's night outside, using that command will make it night in-game. If it's morning outside, using that command will make it morning in-game. Enjoy!
Dedicated Server Download
Non-dedicated Server Download
Please note: This uses your computer's time. Please make sure your computer's clock is set correctly. Otherwise, it wont work as intended.
Updates:
v1.2
-Changed command from /syncday to /synctime
-Changed if statement spam into 1 switch statement
-Made the sync more realistic. I added more variety to the times of day.
v1.3
-Changed nonexistent hour 24 to existent hour 0
-Added a dedicated server edition download
-Removed unused checks
« Last Edit: April 07, 2015, 03:20:45 PM by -Setro- »

setro
two things
1: learn about a switch statement
Code: [Select]
switch(%var)
{
    case 1:
        code;
    case 2:
        code;
}

this will trim down your program by at least a third the lines, and will look unimaginably prettier

2: your program will sort of malfunction on a hosting service or remote server
not necessarily break, just provide unexpected results - the hosting service is presumably hosting in a different timezone than the player.

there's an easy solution to this - just make a client mod. when the user does /syncday (why isn't it 'synctime' or 'syncdaycycle'? those names are less ambiguous and a little more precise), if they have the client mod, get the time from the user's clock via the client mod, then set the daycycle to that instead.

also, i'm not certain, but this mod will only sync up "morning, noon, and evening" not the precise time of day. you can make this better with math, setro - maybe something like 1 / hour of day = offset

Thanks setro. I was planning on using this for my lego creator freebuild.

-snip-
1. I'm not used to switch statements, if you could give me an example on how to use them, I'll convert to switch statements
2. I'll try to release a client-sided mod, now that you brought that up
3. Seems like a good method, I'll use that if it works out nicely

now:
Code: [Select]
if(%time == 1) {
serverCmdEnvGui_SetVar(%client, DayOffset, 0.68718);
}
if(%time == 2) {
serverCmdEnvGui_SetVar(%client, DayOffset, 0.68718);
}
if(%time == 3) {
serverCmdEnvGui_SetVar(%client, DayOffset, 0.68718);
}
...
then:
Code: [Select]
  switch(%time) {
    case 1:
      serverCmdEnvGui_SetVar(%client, DayOffset, 0.68718);
    case 2:
      serverCmdEnvGui_SetVar(%client, DayOffset, 0.68718);
    case 3:
      serverCmdEnvGui_SetVar(%client, DayOffset, 0.68718);
...

Also, learn proper indentation:
Code: [Select]
function () {
    block {
        statement;
    }
}

as it stands, you have none at all, which is better than inconsistent indentation by a long shot, but still rather difficult to read

I didn't consider it originally, but the client sided mod should be able to function completely independently from the server based version, and is inherently superior.
stuff, you don't even have to change much - just make a way to trigger it somehow (like a button on the environment gui maybe?) and change all the serverCmdThing(%client, args) calls to commandToServer('thing', args)
« Last Edit: April 06, 2015, 08:01:07 PM by Lugnut »

Also, learn proper indentation:
Code: [Select]
function () {
    block {
        statement;
    }
}

as it stands, you have none at all, which is better than inconsistent indentation by a long shot, but still rather difficult to read
I hate that indentation style. I prefer:
Code: [Select]
function ()
{
block
{
statement;
}
}

But how is the script going to know which case to use?

no see that's formatting, we'll fix that later, i agree
i'm showing him indentation right now

baby steps, jes, baby steps
But how is the script going to know which case to use?
because switch(%time)
%time should be an integer between 1 and 24, inclusive. so... that's just how it works. not sure exactly what you mean, actually.

But how is the script going to know which case to use?
What do you mean?

When %time is the value of the case number, then that code will be called.
Code: [Select]
switch(%time)
{
case 0:
echo("Poodles");

case 77:
echo("Lucky!");

case 666:
echo("EVIL!!!");
}
When %time == 0, "Poodles" will be echoed.
When %time == 77, "Lucky!" will be echoed.
When %time == 666, "EVIL!!!" will be echoed.

ohhh
those are super useful. thanks.
as far as the formatting, notepad++ does that automatically, i just used notepad for some reason

i just used notepad for some reason
one does not simply use a dramatically inferior editor for stuffs and giggles if one wishes to become coding god

ohhh
those are super useful. thanks.
as far as the formatting, notepad++ does that automatically, i just used notepad for some reason
You can also do switch statements with strings.
Code: [Select]
switch$(%string)
{
case "Poodles":
%var = 0;

case "Lucky!":
%var = 77;

case "EVIL!":
%var = 666;

default:
%var = -1;
}
(The default case will be called any time that the switch doesn't match any of the cases. You can also use the default case when you're not using a string switch)

Then you can get complex :P
Code: [Select]
switch$(%string)
{
case "beef" or "cow" or "pork" or "pig":
%food = "Meat";

case "banana" or "apple" or "pear":
%food = "Fruit";

case "broccoli" or "carrot" or "string cheese":
%food = "vegetable";

default:
%food = "Unknown";
}

one does not simply use a dramatically inferior editor for stuffs and giggles if one wishes to become coding god
I only use TextEdit.
« Last Edit: April 07, 2015, 07:21:07 AM by jes00 »

statement amended:
one does not simply use a dramatically inferior editor after using one that feels superior for stuffs and giggles if one wishes to become coding god
in other words, go back to notepad++, don't make yourself insane

look at what happened to jes
he uses textedit
he's insane

don't do that to yourself