First things first if this is in the wrong section feel free to move it.
I saw mod help and just went for it.
OK for the question.
I have computer craft installed and wanted to make a program that will turn my lights on and off.
I'm not that skilled with lua and made this:
local functionOn = "On"
local functionOff = "Off"
local side = "right"
print("would you like to turn your lights on or off?")
local input = read()
if input == fucntionOn then
rs.setOutput(side,false)
else
if input == functionOff then
rs.setOutput(side,true)
end
end
I want it to repeat but I can't seem to make it do that.
the code works completly but if put while true do or repeat or any thing else for a loop it says no. I would also like it if i could get rid of local input = read("*")
local side = "right"
while true do
print("Would you like to turn your lights on or off?")
local input = read()
local inputLower = string.lower(input)
if inputLower == "on" then
rs.setOutput(side,false)
elseif inputLower == "off" then
rs.setOutput(side,true)
else print("Input not recognised!")
end
sleep(1)
end
Loops in Lua will not work unless they pause (sleep(time)). It's also a good idea to use string.lower() as above so that if you enter OfF, it will still recognise it as off.
Additionally, else if is compacted into elseif in Lua.
local side = "right"
while true do
print("Would you like to turn your lights on or off?")
local input = read()
local inputLower = string.lower(input)
if inputLower == "on" then
rs.setOutput(side,false)
elseif inputLower == "off" then
rs.setOutput(side,true)
else print("Input not recognised!")
end
sleep(1)
end
Loops in Lua will not work unless they pause (sleep(time)). It's also a good idea to use string.lower() as above so that if you enter OfF, it will still recognise it as off.
Additionally, else if is compacted into elseif in Lua.
Thanks i'll try it! You've helped out alot!
New to lua so still learning
This is a lot easier to do than just put a lever down and flip it!
while true do
print("Would you like to turn your lights on or off?")
local input = read()
local inputLower = string.lower(input)
if inputLower == "on" then
rs.setOutput(side,false)
term.setclear()
term.setCursorPos(1,1)
elseif inputLower == "off" then
rs.setOutput(side,true)
term.setclear()
term.setCursorPos(1,1)
else print("Input not recognised!")
end
I saw mod help and just went for it.
OK for the question.
I have computer craft installed and wanted to make a program that will turn my lights on and off.
I'm not that skilled with lua and made this:
local functionOn = "On"
local functionOff = "Off"
local side = "right"
print("would you like to turn your lights on or off?")
local input = read()
if input == fucntionOn then
rs.setOutput(side,false)
else
if input == functionOff then
rs.setOutput(side,true)
end
end
I want it to repeat but I can't seem to make it do that.the code works completly but if put while true do or repeat or any thing else for a loop it says no.
I would also like it if i could get rid of local input = read("*")local side = "right" while true do print("Would you like to turn your lights on or off?") local input = read() local inputLower = string.lower(input) if inputLower == "on" then rs.setOutput(side,false) elseif inputLower == "off" then rs.setOutput(side,true) else print("Input not recognised!") end sleep(1) endLoops in Lua will not work unless they pause (sleep(time)). It's also a good idea to use string.lower() as above so that if you enter OfF, it will still recognise it as off.
Additionally, else if is compacted into elseif in Lua.
Stu
Thanks i'll try it! You've helped out alot!
New to lua so still learning
This is a lot easier to do than just put a lever down and flip it!
local side = "bottom"
while true do
print("Would you like to turn your lights on or off?")
local input = read()
local inputLower = string.lower(input)
if inputLower == "on" then
rs.setOutput(side,false)
term.setclear()
term.setCursorPos(1,1)
elseif inputLower == "off" then
rs.setOutput(side,true)
term.setclear()
term.setCursorPos(1,1)
else print("Input not recognised!")
end
sleep(0)
end
If you're encountering issues, make sure the sleep time is more than 0, and post the error the computer prints when trying to run the file.
Stu