ok so I like to have a computer display if there's power or not on a tekkit server
win I run the program I get a error line 11 attempt to index ? (a nil value)
can some one help me find what is wrong
while true do
side = "right"
if redstone,getInput("left", "true")
then mon = peripheral,wrap(side, true)
mon.setTexScale(1)
mon.setCursorPos(1,1)
mon.write("power NO")
sleep(2.0)
mon.clear()
else
mon.setTexScale(1)
mon.setCursorPos(1,1)
mon.write("OUT OF POWER")
sleep(2.0)
mon.clear()
end
end
You only assign mon in the first condition, in the else condition, you are using mon before it exists.
If you format your code properly, it should look more like this:
while true do
side = "right"
if rs.getInput("left", "true") then
mon = peripheral,wrap(side, true)
mon.setTexScale(1)
mon.setCursorPos(1,1)
mon.write("power ON")
sleep(2.0)
mon.clear()
else
mon.setTexScale(1)
mon.setCursorPos(1,1)
mon.write("OUT OF POWER")
sleep(2.0)
mon.clear()
end
end
here you can see that mon is being assigned after the if, and not in the else section, therefore mon does not exist in the else condition, thus: an error.
Just move the mon declaration outside of the if statement and it should work fine.