This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ryanjr's profile picture

Question posted in an unrelated thread.

Started by ryanjr, 14 September 2013 - 10:28 AM
ryanjr #1
Posted 14 September 2013 - 12:28 PM
Hello, i have the same problem but that didn't fix it, sadly.

This is a code for running the time over and over again on a monitor. As far is I know, there is no command to automatically show the time on the monitor so if you could solve that too, it would be great. Anyway, i'm getting the error:

:bios:383: [string "time"]:1: '<name>' expected

Heres the code:

function = T –Line 1 obviously
term.clear()
term.setCursorPos(1,1)
local time = os.time()
time = textutils.formatTime(time, false)
print("The time is "..time)
end


for T = 0, 9999999999999999999 do
function T
sleep(1)
end

Please help.
Yevano #2
Posted 14 September 2013 - 12:58 PM
That's incorrect syntax for defining a function. Also, the second line of that red bit is incorrect for calling the function. Use function T() to start the definition and T() to call it. Look here for an example on correct syntax.

EDIT: You also shouldn't use the same names for both your function and the iterator variable in your for loop. In fact, you don't even need a for loop if the loop runs forever. Just use while true do.
ryanjr #3
Posted 14 September 2013 - 01:06 PM
Thank you, I totally forgot how to use functions.