hello
I'm trying to use a computer to turn my reactor off an on again, but when I ran my program, it said
'attempt to index ? (a nil value)
this is my code
mon = peripheral.wrap("top")
mon.clear()
mon.setTextScale(1)
mon.write("REACTOR 1")
input = read()
if input == "turn off" then
redstone.setOutput("back", true)
mon.clear()
mon.write("turned off")
sleep(3)
mon.clear()
mon.write("REACTOR 1")
end
if input == "turn on" then
redstone.setOutput("back", false)
mon.clear()
mon.write("Turned on")
sleep(3)
mon.clear()
mon.write("REACTOR 1")
end
8 replies to this topic
#1
Posted 08 September 2012 - 10:17 PM
#2
Posted 08 September 2012 - 10:22 PM
Line number that the error is at?
Edit: Also this thread needs to be in Ask a Pro section.
Edit: Also this thread needs to be in Ask a Pro section.
#3
Posted 08 September 2012 - 10:25 PM
oh sorry, I'm new, the line number is 2 I think
#4
Posted 08 September 2012 - 10:27 PM
I put the coding in the startup bit and it says 'startup:2: attempt to index ? (a nil value)
#5
Posted 08 September 2012 - 10:34 PM
It looks like the monitor isn't on the top of the computer. In the first line check that the side you put is the one the monitor is on.
#6
Posted 08 September 2012 - 10:46 PM
it's working now, but the monitor isn't displaying the text and the redstone isn't turning on :/
#7
Posted 08 September 2012 - 10:48 PM
and do you know how I can program the computer to loop back, so I can turn the reactor off and turn it off again without rebooting?
#8
Posted 08 September 2012 - 10:55 PM
Here you go:
local mon = peripheral.wrap("top")
if not mon then
print("Monitor not found")
return
end
-- function to clear the monitor
local function clear()
mon.clear()
mon.setCursorPos(1, 1)
end
clear()
mon.setTextScale(1)
mon.write("REACTOR 1")
while true do -- infinite loop, will repeat the code inside forever (or until you break it or terminate the program)
local input = read()
if input == "turn off" then
rs.setOutput("back", true)
clear()
mon.write("Turned OFF")
sleep(3)
clear()
mon.write("REACTOR 1")
elseif input == "turn on" then
redstone.setOutput("back", false)
clear()
mon.write("Turned ON")
sleep(3)
clear()
mon.write("REACTOR 1")
end
end
#9
Posted 08 September 2012 - 11:27 PM
thanks
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











