I am new to this community( my first post) so I don't know if this problem was discussed before or not.
The problem is REALLY wierd, at least in my opinion. I have experience with several programming languages, but not with LUA. However, I do know one thing - outputting a text could not brake a program. Lua tries to contradict me.
Here is the story.
I tried for several hours to create a program to control my farm. My purpose was to make an interface asking for "char" events. But the snag here was to add start and stop functionality to the same button and the program interface to react accordingly. For example, when I pressed 1 the first time, the program should have sent a redstone signal and the message in the interface should have gone from Start to Stop the respective engine, but when I pressed 1 again, it should have stopped that and came back to the original text information.
I managed to get that to work using tables and I really thought I overcame the toughest problem of the code. From there on, it was just a matter of time to add more functionality in the if statements.
Now, I have a monitor connected to my computer.
When I pressed 1, I wanted my monitor to display - "Part of the factory - ON".
Without thinking that something could go wrong in adding some text output, I went on and added all of my monitor text in the file. I am 100% sure my code is correct regarding the monitor matter, but something wierd happens.
When I test my code now and I try to press the 1 button, the text in the interface doesn't change anymore, it only outputs the information on the monitor, but it never goes to the ON state, although it did before. I tried to remove all the monitor text I added, but the problem persists. I don't understand WHY. The code is the same as it was before the monitor addition and it worked then….
Here is the pastebin:
monitor = peripheral.wrap("left")
monitor.setTextScale(1)
fermenter = 0
squeezer = 0
melon = 0
tree = 0
entire = 0
color1 = colors.white
color2 = colors.lightBlue
color3 = colors.orange
color4 = colors.green
term.clear()
term.setCursorPos(1,1)
print("**************** Farm Software *******************")
print("**************************************************")
print(" ")
print("** Choose what you want to do **")
print("** 1. Start the fermenter **")
print("** 2. Start the squeezer **")
print("** 3. Start the melon farm **")
print("** 4. Start the tree farm **")
print("** 5. Start the entire farm **")
print("** 6. Exit **")
print(" ")
print("**************************************************")
monitor.clear()
monitor.setCursorPos(1,1)
monitor.write(" ")
monitor.write(" ")
monitor.write(" ")
monitor.write(" ")
monitor.write("|-------------------- Farm Software --------------------|")
monitor.write("| |")
monitor.write("| Fermenter | OFF |")
monitor.write("|-------------------------------------------------------|")
monitor.write("| Squeezer | OFF |")
monitor.write("|---------------------------------- --------------------|")
monitor.write("| Melon Farm | OFF |")
monitor.write("|-------------------------------------------------------|")
monitor.write("| Tree Farm | OFF |")
monitor.write("|-------------------------------------------------------|")
keys = {"1", "2", "3", "4", "5", "6"}
function responsiveInterface()
while true do
event, key = os.pullEvent("char")
for i = 1, #keys do
if key == keys[1] then
if fermenter == 0 then
fermenter = 1
rs.setBundledOutput("back", color1)
term.setCursorPos(1,5)
term.clearLine()
print("** 1. Stop the fermenter **")
monitor.setCursorPos(1,7)
monitor.clearLine()
monitor.write("| Fermenter | ON |")
else
fermenter = 0
rs.setBundledOutput("back", color1-color1)
term.setCursorPos(1,5)
term.clearLine()
print("** 1. Start the fermenter **")
monitor.setCursorPos(1,7)
monitor.clearLine()
monitor.write("| Fermenter | OFF |")
end
elseif key == keys[2] then
if squeezer == 0 then
squeezer = 1
term.setCursorPos(1,6)
term.clearLine()
print("** 2. Stop the squeezer **")
monitor.setCursorPos(1,9)
monitor.clearLine()
monitor.write("| Squeezer | ON |")
else
squeezer = 0
term.setCursorPos(1,6)
term.clearLine()
print("** 2. Start the squeezer **")
monitor.setCursorPos(1,9)
monitor.clearLine()
monitor.write("| Squeezer | OFF |")
end
elseif key == keys[3] then
if melon == 0 then
melon = 1
term.setCursorPos(1,7)
term.clearLine()
print("** 3. Stop the melon farm **")
monitor.setCursorPos(1,11)
monitor.clearLine()
monitor.write("| Melon Farm | ON |")
else
melon = 0
term.setCursorPos(1,7)
term.clearLine()
print("** 3. Start the melon farm **")
monitor.setCursorPos(1,11)
monitor.clearLine()
monitor.write("| Melon Farm | OFF |")
end
elseif key == keys[4] then
if tree == 0 then
tree = 1
term.setCursorPos(1,8)
term.clearLine()
print("** 4. Stop the tree farm **")
monitor.setCursorPos(1,13)
monitor.clearLine()
monitor.write("| Tree Farm | ON |")
else
tree = 0
term.setCursorPos(1,8)
term.clearLine()
print("** 4. Start the tree farm **")
monitor.setCursorPos(1,13)
monitor.clearLine()
monitor.write("| Tree Farm | OFF |")
end
elseif key == keys[5] then
if entire == 0 then
entire = 1
fermenter = 1
squeezer = 1
melon = 1
tree = 1
term.setCursorPos(1,5)
term.clearLine()
print("** 1. Stop the fermenter **")
term.setCursorPos(1,6)
term.clearLine()
print("** 2. Stop the squeezer **")
term.setCursorPos(1,7)
term.clearLine()
print("** 3. Stop the melon farm **")
term.setCursorPos(1,8)
term.clearLine()
print("** 4. Stop the tree farm **")
term.setCursorPos(1,9)
term.clearLine()
print("** 5. Stop the entire farm **")
else
entire = 0
fermenter = 0
squeezer = 0
melon = 0
tree = 0
term.setCursorPos(1,5)
term.clearLine()
print("** 1. Start the fermenter **")
term.setCursorPos(1,6)
term.clearLine()
print("** 2. Start the squeezer **")
term.setCursorPos(1,7)
term.clearLine()
print("** 3. Start the melon farm **")
term.setCursorPos(1,8)
term.clearLine()
print("** 4. Start the tree farm **")
term.setCursorPos(1,9)
term.clearLine()
print("** 5. Start the entire farm **")
end
elseif key == keys[6] then
term.setCursorPos(1,1)
term.clear()
return
end
end
end
end
responsiveInterface()
If anyone has any idea about this bug, please tell me. Or , it might something wrong in the code that I don't know…
Thanks a bunch!