while true do
side = "" -- Top, bottom, left, right, front, back, WHATEVER YOU CHOOSE
local time = os.time()
time = textutils.formatTime(time, false)
mon = peripheral.wrap(side, true)
mon.setTextScale(5)
mon.setCursorPos(1,1)
mon.write(time)
sleep(0.1)
mon.clear()
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
collection of usfull scripts
Started by twig1233, 26 July 2012 - 04:14 PMPosted 26 July 2012 - 06:14 PM
basic clock that prints on a monitor
Posted 26 July 2012 - 06:25 PM
Quick suggestion: Make a variable for the side instead of using "top" because anyone who uses it will wrap on top. You want this to be a choice.
Posted 26 July 2012 - 06:51 PM
and how would i go about doin that i only started using computer craft 2 days ago and still learning lua
Posted 26 July 2012 - 06:56 PM
Add this at the top
side = "" -- Top, bottom, left, right, front, back, WHATEVER YOU CHOOSE
Then make the "top"; sidePosted 26 July 2012 - 07:08 PM
do u think it would be possible to make a day counter
Posted 26 July 2012 - 07:11 PM
Yes, do an if statement.
if os.time() == 12 then
day = day + 1
end
Something like that… I'm not really familiar with the whole os.time().Posted 26 July 2012 - 07:35 PM
too long without yeilding
Posted 26 July 2012 - 07:54 PM
Did you get rid of the sleep? You need the sleep (if not event) for a while true loop.
Posted 26 July 2012 - 08:29 PM
i think iv fixed it
nope still getting errors any advice
local time = os.time()
if time == 23 then
day = day+1
else
side = "top" -- Top, bottom, left, right, front, back, WHATEVER YOU CHOOSE
time = textutils.formatTime(time, false)
mon = peripheral.wrap(side, true)
mon.setTextScale(5)
mon.setCursorPos(1,1)
mon.write(time)
mon.setCursorPos(1,2)
mon.write("Day="..day)
sleep(0.1)
mon.clear()
shell.run("startup")
end
nope still getting errors any advice
Posted 26 July 2012 - 09:50 PM
Well, first of all, please say what the error actually is.
If the error is
Currently, the only mention of day before the line that this error occurs on (10), is this:
You need to assign day to 1 before this:
Other than this, why are you running startup all over again? This doesn't really work well, as the user may not want to run it on startup. This is a version of the script with some fixes:
If there's anything new in the script that I didn't fully explain, feel free to ask.
If the error is
name:10: attempt to concatenate string and nil
then it is because you never defined the base value for day, making its value nil (an empty variable).Currently, the only mention of day before the line that this error occurs on (10), is this:
if time == 23 then
day = day+1
(Just a note, the way the code is set up right now doesn't really make sense. Why would it not print if it's a new day?)You need to assign day to 1 before this:
local day = 1
Other than this, why are you running startup all over again? This doesn't really work well, as the user may not want to run it on startup. This is a version of the script with some fixes:
local tArgs = { ... } -- This gets arguments after "filename", i.e. "<filename> <side>"
assert(#tArgs == 1,"Usage: <name> <side>") -- If tArgs has more or less than 1 element, print "Usage: <name> <side>" and terminate.
while true do
local time = os.time()
local day = 1
if time == 23 then
day = day+1
end
time = textutils.formatTime(time, false)
mon = peripheral.wrap(tArgs[1], true)
mon.setTextScale(5)
mon.setCursorPos(1,1)
mon.write(time)
mon.setCursorPos(1,2)
mon.write("Day: "..day)
sleep(0.1)
mon.clear()
end
end
If there's anything new in the script that I didn't fully explain, feel free to ask.
Posted 27 July 2012 - 01:26 AM
wen it gets to 11pm it gos to 2 then jumps back up to 1
Posted 27 July 2012 - 01:28 AM
What you mean resets to 0 then jumps 1?
Like day = 0, day = 1?
Like day = 0, day = 1?
Posted 27 July 2012 - 01:43 AM
because
local day = 1
is under
while true do
so its looping and resetingPosted 27 July 2012 - 06:22 PM
Whoops, sorry. You can easily fix that yourself, though, I reckon.becauseis underlocal day = 1
so its looping and resetingwhile true do
Posted 30 July 2012 - 10:29 AM
How would I go about doin that, like I said the other day im new to lua, java is more my cup of tea.