99 posts
Location
Scotland!
Posted 08 October 2012 - 06:41 PM
I was planning on making a minecraft clock, but I dont think It would work unless it can continue working when my minecraft server starts up again. do computers work like that? and if so is there any lag between minecraft day/night cycle beginning starting and the computer?
436 posts
Posted 08 October 2012 - 06:58 PM
Ehmmmm. Okay, so if you are trying to make a clock that measures minecraft time, then it won't matter, because you can just have it pull os.clock().
However, a real-time clock will not simply continue if the server is shut down and started back up. You can always store whatever time it is when you stop the clock, and then bring that information back, but that would not be very beneficial if you turn the mc server off, because it won't know how long the server has been offline.
521 posts
Location
Stockholm, Sweden
Posted 08 October 2012 - 07:00 PM
Instead of using like sleep(1) for each second, you could use os.clock() to check the time.
And this will fix the time when rebooted, so the time isn't off set.
Wiki:
http://computercraft.info/wiki/
2217 posts
Location
3232235883
Posted 08 October 2012 - 07:01 PM
well then once the computer is unloaded while the server is still on it will be innacurate
you could make a batch file to run outside the server writing the current time to a file inside of the computers folder
99 posts
Location
Scotland!
Posted 08 October 2012 - 07:36 PM
well then once the computer is unloaded while the server is still on it will be innacurate
you could make a batch file to run outside the server writing the current time to a file inside of the computers folder
even with chunkloaders / world anchors?
474 posts
Posted 08 October 2012 - 07:40 PM
well then once the computer is unloaded while the server is still on it will be innacurate
you could make a batch file to run outside the server writing the current time to a file inside of the computers folder
even with chunkloaders / world anchors?
Computers will stay loaded with chunk loaders and world anchors.
99 posts
Location
Scotland!
Posted 08 October 2012 - 07:44 PM
Ehmmmm. Okay, so if you are trying to make a clock that measures minecraft time, then it won't matter, because you can just have it pull os.clock().
However, a real-time clock will not simply continue if the server is shut down and started back up. You can always store whatever time it is when you stop the clock, and then bring that information back, but that would not be very beneficial if you turn the mc server off, because it won't know how long the server has been offline.
ok, that makes making a monitor surrounded clock tower much easier, I suppose I could make a clock that measures the total time that the server is on, might be cool because we spend a lot of time on our server. I could do it by updating the realtime calculation every tick, and then somehow saving the time to a file for starting up again, I think It could only work with the command block in 1.4 though (i.e. shut off the server and save the time simultaniously using redstone).
436 posts
Posted 08 October 2012 - 07:53 PM
Actually, saving to a file takes something like .7 ticks. So, if you have a while loop with a 1 second sleep, you can save just before the sleep like so:
file = fs.open("time", "w")
if hrs<10 then
sHrs = "0"..tostring(hrs)
end
if min < 10 then
sMin = "0"..tostinrg(min)
end
file.write(sHrs.." "..sMin)
file.close()
And then to load it back, use this:
file = fs.open("time", "r")
tTime = file.readLine()
hrs = tonumber(string.sub(tTime, 1, 2))
min= tonumber(string.sub(tTime, 4, 5))
file.close()
252 posts
Posted 09 October 2012 - 02:53 AM
Also use startup as the file name so that you do not have to restart the program every time you start the server. Or whenever the server is started.