Jump to content




[LUA] Need help, and operator!


  • You cannot reply to this topic
3 replies to this topic

#1 1337patchy

  • Members
  • 15 posts

Posted 05 July 2012 - 10: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?

#2 cant_delete_account

  • Members
  • 484 posts

Posted 05 July 2012 - 10: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

#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 05 July 2012 - 10: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


#4 1337patchy

  • Members
  • 15 posts

Posted 05 July 2012 - 10: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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users