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

[LUA] Need help, and operator!

Started by 1337patchy, 05 July 2012 - 09:19 PM
1337patchy #1
Posted 05 July 2012 - 11:19 PM

local time = os.time()
time = textutils.formatTime(time, true)
local side = "left"
term.clear()
term.setCursorPos(1,1)
print("Time: "..time)
if time >=8 and <=17 then
rs.setOutput(side, true)
print("Livestock acess granted")
sleep(2)
os.shutdown()
else
print("Unsafe at night!, return later!")
os.shutdown()
end

Hello :P/>/> I get a problem on the line "if time >=8 and <=17 then" saying i get an unepexted symbol :s
I really dont know how to get rid of the error and make the program work, any help please?
cant_delete_account #2
Posted 05 July 2012 - 11:25 PM
Here:
local time = os.time()
time = textutils.formatTime(time, true)
local side = "left"
term.clear()
term.setCursorPos(1,1)
print("Time: "..time)
if time >=8 and time <=17 then
rs.setOutput(side, true)
print("Livestock acess granted")
sleep(2)
os.shutdown()
else
print("Unsafe at night!, return later!")
os.shutdown()
end

You need to include the variable on the part after the and
MysticT #3
Posted 05 July 2012 - 11:29 PM
Also, you convert the variable to a string, so you can't compare it. Try with this:

local time = os.time()
local sTime = textutils.formatTime(time, true)
local side = "left"
term.clear()
term.setCursorPos(1,1)
print("Time: "..sTime)
if time >= 8 and time <= 17 then
  rs.setOutput(side, true)
  print("Livestock acess granted")
  sleep(2)
  os.shutdown()
else
  print("Unsafe at night!, return later!")
  os.shutdown()
end
1337patchy #4
Posted 05 July 2012 - 11:29 PM
Hello, thank you for your reply. I continued trying even after posting, and i did try that, but i got an error, trying to compare string and number, got string or so. Then i put the 8 and 17 in quotes, and it considered it was night.. I removed the quotes and the "time = textutils.formatTime(time, true)" line..
Now it works :P/>/>
Thanks though!


EDIT: Posted too late, as mentioned above, thats right :)/>/> Thanks all but thankfully i managed to get there on my own, i keep on trying even after asking for help. Thanks a lot!