Space Engineers

Space Engineers

Not enough ratings
Arch's Planetary Local Clock
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
12.982 KB
31 May, 2020 @ 2:17pm
13 Jun, 2020 @ 5:34am
3 Change Notes ( view )

Subscribe to download
Arch's Planetary Local Clock

Description
Introduction and Basic Usage
Ever been stuck on planet and wondered how long it is before dawn?


This script adds a clock for planetary bases, so you can see the local time. It works by assuming the day/night cycle (i.e. "year" ) is of a particular length (default is 2 hours) and resetting periodically. You can either do this manually - for example, running with the argument "6" will reset the clock to 6am (dawn) - or you can use a solar panel.


Note that this doesn't show the real world time - it's the local time on the planet you're on. For the real world time - and many other functions - I can recomment MMaster's excellent Automatic LCDs 2 script. No doubt there are many alternatives.


To show the clock on an LCD or text panel, add "[Clock]" to the panel's name. The prog block on which the script is running will automatically show the clock on its display.


To reset with a solar panel, set up a panel in a clear spot and add "[Clock]" to its name. When the panel gets light after a long period of darkness the clock will reset to 6am. True dawn will be a little while after this - solar panels start to emit power in pre-dawn light.


It's not guaranteed to be 100% correct - it may speed up or slow down, relying as it does on the TimeSinceLastRun mechanism. However, it should only be out by a few minutes every day, and using a solar panel to reset it will bring it back into time every day.


Scheduler
It's also possible to tell the script to do things at certain times. To do this, you need to edit the Custom Data and add text.
Each item in the schedule should be on a line by itself, and looks like this:
hours mins command...
where hours and mins are either:
  • single numbers indicating the hour and minute when the event should occur
  • a range of numbers, so "12-15 20" (hours is "12-15" and mins is "20") will happen at 12:20, 13:20, 14:20 and 15:20
  • a comma-separated list of numbers, so "10,11,12 0,5,10,15,20,25,30,35,40,45,50,55" (note the space between 12 and 0, separating the hours from the minutes) will happen every five minutes between 10am and 12:55pm.
  • An asterisk "*" meaning "all values"
Those of you intimately familiar with Unix/Linux systems will recognise this as a very cut-down and slightly reordered version of a crontab.

The rest of the line, after the time elements, is a command. This can be:
  • on blockname to turn a block on (see below for how blocknames work)
  • off blockname to turn a block off (see below for how blocknames work)
  • action blockname action to perform an Action on a block - actions are listed on the Space Engineers wiki in the Action List[www.spaceengineerswiki.com]
  • run blockname argument to run another programmable block's script with a given argument
  • reseton / resetoff (see Enabling/Disabling Solar Reset below)
The blockname is either:
  • A string which the name of the block contains - if there's more than one block containing that string, the command will run on all blocks which contain the string
  • G: followed by a group name which must be exactly correct - this will run the command on all blocks in the group
At the moment, blocknames cannot contain spaces - sorry!


Some examples
  • 8 20 on G:InteriorLights will turn on blocks in the group InteriorLights at 8:20am
  • 10 45,50 action door Open_Off will close all blocks (hopefully doors) whose name contains "door" at 10:45 and 10:50
  • * 30 action foolight OnOff will toggle the On/Off status of all blocks with "foolight" in the name on the half-hour (i.e. 00:30, 01:30 and so on for all hours)
  • 10,11 0,30 run MyProgBlock wibble will run the script on the programmable block MyProgBlock with the argument "wibble" at 10:00, 10:30, 11:00 and 11:30


IMPORTANT: the script will only read the contents of the Custom Data text and turn it into a schedule when you tell it to. You must run the script with the argument "customdata" or "cd" whenever you change the schedule.




Enabling/Disabling Solar Reset
Sometimes you may need to temporarily turn off the automatic reset when the solar panel gets light. To do this, run the block with the argument resetoff to turn off solar resetting, or reseton to turn it back on. Because of how I've written the code, you can also use these in a schedule (although I doubt there's any point).




8 Comments
AenesidemusOZ 29 Jun, 2022 @ 10:19pm 
Great concept! Thanks for doing this instead of, you know, working. ;-)
Walto 14 Jun, 2020 @ 12:38am 
First, thanks a lot !! :D
I'll give it a try in the next few days :)

Then, Waaaaah !!! Easier, sure, but DAMN that's interesting !
Thanks for sharing !
archfalhwyl  [author] 13 Jun, 2020 @ 7:05am 
Update! The script now has scheduling and a way of turning the reset mechanism on and off. I've tested the scheduler as much as I sensibly can at the moment. The algorithm is a bit hairy in places because I insisted on doing it optimally like the fool I am.

(well it's easier than going through this damn paper like I'm supposed to be doing: https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/2005JE002444 )

Walto 7 Jun, 2020 @ 3:13pm 
Oh waw nice :D !
Your new job looks amazing !!

Yeah, I wanted to do that because I have a mobile station which stays a moment at its location sometimes, so it needs to be reseted when I am at my new location, but not necessary for the journey each time my solar panels detect the sun :)

Your future scheduling stuff sounds great too !!
archfalhwyl  [author] 7 Jun, 2020 @ 2:44pm 
Well, I got bored and wrote the scheduling stuff :)

I'll put it up when it's good and tested - the problem with this time-based stuff is you have to sit around for hours in the game to test it!

The basic idea is that you create your schedule in Custom Data, and it might look something like this:

18 0 on MainLight
18 10 off G:Lights
* 5,10,15,20,25,30,35,40,45,50,55 action Door Open_Off

and so on.

The first two parts are hours and minutes, where you can give a number, a set of numbers separated by commas, a range (like 10-20) or "*" for "all". So the first line does its action at 6pm, the second at 6:10pm, and the last at every hour, every five minutes.
archfalhwyl  [author] 7 Jun, 2020 @ 6:09am 
It's the "then do that" part which is hard ;)

I've thought about it, and think I can at least provide "turn block on/off at a given time" and "run program on progblock with argument at given time." That should do for most things. I'll probably put it as Custom Data on the clock's progblock. Something like:

0600 [MyLightGroup] on (groups have [ ] around them)
0600 MyLightBlock off
1200 MyProgBlock run someargument

and maybe add some special commands, like

resetoff / reseton

I'm still not sure why you want to be able to do that!


It might be some time before I get around to this - I've got actual work to do (exciting stuff too - I've just landed a job writing code to help analyse images from the European Mars Rover!)
archfalhwyl  [author] 6 Jun, 2020 @ 11:23am 
I'm not really sure what you're asking for - you want to be able to turn off the 6am reset once it has happened once? Well, I can easily do that, but the clock will drift.

I like the idea of triggering events at certain times and I'll look into it - might be tricky, though, because of how the API works. I'd have to write a huge amount of code to handle every possible interaction with a block!
Walto 5 Jun, 2020 @ 8:55am 
Thank you ! I was looking for something doing this without mod and you nailed it :D !
Is it possible to make the script updating his self by solar panel just once or by a command, so we don't have to rename the solar panel again to avoid the refresh each day cycle ? :)
Lots of ideas can come with your script !
Like, "at 4:20pm -> toggle Timer"
Or past "6pm -> Off the lights"
etc !
Thanks, have a good day commander! :)