문제

I'm trying to make an analog clock display the time (12-hour) and I have to use Lua. I use the following line to get the time in this format:

os.date('%I:%M')

This apparently doesn't work as I keep getting a nil error, this is the only thing wrong with the code. os.time works fine but not os.date; I even tried without the '%I:%M' (The format for the time) and it still doesn't work with os.date().

What am I doing wrong? Do I have to import the date function from some other library? I am a total Lua nooby BTW...

I'm actually using it to work monitors for ComputerCraft on Minecraft but the code is:

m = peripheral.wrap('back')
m.setTextScale(5)
while i == i do
m.clear()
m.setCursorPos(1,1)
x = os.date('%I:%M')
m.write(x)
sleep(60)
end

The thing is though that the rest of the code doesn't affect it. The os.date is the only problem because I try it seperately and it gives me the same error "attempt to call nil".

도움이 되었습니까?

해결책

According to this, ComputerCraft doesn't appear to expose os.date(). A workaround is suggested here:

Unfortunately the date and time are not exposed to us. In Lua, the os.date() and os.time() functions would be what we want, however in ComputerCraft date is not implemented and time gives the minecraft time.

The only way I know of to get the real date and time is to get it from the web using the http API.

다른 팁

also, if you want the minecraft date, try using os.getday()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top