When you click one of the buttons, it does what I want it to do, but because I have it doing
while true do
to test for the pressing of buttons, so if you mis-click the program doesn't stop, that means while it is doing its thing,(scanning or wiping the computer) It is still testing for button presses in that certain area. The only way around this, I think, is to
break the while true do loop, but whenever I put break, it keeps asking for end's to close the if's that I put.
The Exact error:
Bios:338: [string:"startup"]:103:'end' expected (to close 'if' at line 101)
Code:
--Functions
infectedfiles = 0
j = shell.getRunningProgram()
function scan()
--Keywrods to look for in files
bad = {"os.reboot()", "hacked", "virus", "infected"}
--DO NOT EDIT PAST THIS LINE
gb = 0
badfiles = {}
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.blue)
term.write("Mrpoopy MalScan")
term.setCursorPos(1, 2)
term.setTextColor(colors.yellow)
--Make the dots move!
for i = 1, 2 do
term.write("Scanning for viruses.")
sleep(0.5)
term.clearLine()
term.setCursorPos(1,1)
term.write("Scanning for viruses..")
sleep(0.5)
term.clearLine()
term.setCursorPos(1,1)
term.write("Scanning for viruses...")
sleep(0.5)
term.clearLine()
term.setCursorPos(1,1)
end
--Scan all files, looking for keywords
s = fs.list("/")
for _, v in pairs(s) do
h = fs.open(v, "r")
g = h.readAll()
h.close()
for i = 1, #bad do
--If it finds a keyword in the file and the file is not startup
if string.find(g, bad[i]) and v ~= j then
--Make sure it doesnt appear twice
for i = 1, #badfiles do
if v == badfiles[i] then
gb = 0
else
gb = 1
end
end
if gb == 0 then
table.insert(badfiles, v)
infectedfiles = infectedfiles+1
end
end
end
end
term.setCursorPos(15, 1)
term.setTextColor(colors.black)
print("Infected files:")
term.setTextColor(colors.white)
for i = 1, #badfiles do
x, y = term.getCursorPos()
y = y+1
term.setCursorPos(x, y)
print(badfiles[i])
end
end
--Clear computer
function clearcomp()
l = shell.programs()
s = fs.list("/")
for _, v in pairs(s) do
if v ~= j and fs.isDir(v) == false and fs.isReadOnly(v) == false then
fs.delete(v)
print(v)
end
end
for _, v in pairs(l) do
if v ~= j then
fs.delete(v)
print(v)
end
end
end
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(15, 1)
term.setTextColor(colors.lightBlue)
term.write("Mrpoopy MalScan")
term.setCursorPos(14, 4)
term.setBackgroundColor(colors.red)
term.write(" ")
term.setCursorPos(14, 7)
term.write(" ")
term.setTextColor(colors.black)
term.setCursorPos(20, 4)
term.write("Scan")
term.setCursorPos(17, 7)
term.write("Wipe computer")
function menu()
while true do
ev, button, x, y = os.pullEvent("mouse_click")
if x > 9 and x < 29 and y > 3 and y < 5 then
break
term.clear()
term.setCursorPos(1,1)
scan()
menu()
elseif x > 9 and x < 29 and y > 6 and y < 8 then
break
clearcomp()
menu()
end
end
end
menu()
(Sorry for bad indentation)I don't know what is happening here since I have used break many time before.
Any help?