I'm currently trying to make a shop with monitors and computers, and I get errors many times. I know how to solve the errors, but I'm tired of going behind the monitor and click the computer to see the error. I'm using os.run in startup to make it work btw.
This is how it looklikes:
while true do
local success = os.run({}, "program");
print("Press monitor or enter to restart");
local event,par1,par2,par3 = os.pullEvent();
while not (event == "monitor_touch" or (event == "key" and par1 == 28)) do
event,par1,par2,par3 = os.pullEvent();
end
term.setBackgroundColor(colors.black);
term.clear();
term.setCursorPos(1,1);
term.setTextColor(colors.yellow);
term.write("CraftOS 1.7");
term.setCursorPos(1,2);
term.setTextColor(colors.white);
sleep(0.1);
end
But I want to add so that when os.run returns false, I can get the error and print it on the monitor. like
while true do
-- Added errorStr
local success,errorStr = os.run({}, "program");
print("Press monitor or enter to restart");
local event,par1,par2,par3 = os.pullEvent();
while not (event == "monitor_touch" or (event == "key" and par1 == 28)) do
event,par1,par2,par3 = os.pullEvent();
end
-- New Code Starts
if not (success) then
local mon = peripheral.wrap("right");
mon.print(errorStr);
end
-- New Code Ends
term.setBackgroundColor(colors.black);
term.clear();
term.setCursorPos(1,1);
term.setTextColor(colors.yellow);
term.write("CraftOS 1.7");
term.setCursorPos(1,2);
term.setTextColor(colors.white);
sleep(0.1);
end
So I want the os.run to return (true,nil) or (false,"<error string here>").Is there a way to get that error message and if so, how?