This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ziriee's profile picture

Browser Multiple Point Error

Started by Ziriee, 07 September 2013 - 08:56 AM
Ziriee #1
Posted 07 September 2013 - 10:56 AM
Alright everyone. I need help with my file browser, but there seem to be bugs and I can't fix them because it says "Multiple points". I am too lazy to search for them, so if anybody could be crazy and read the whole code and find the bugs, I'd appreciate it alot.

Important stuff:
SpoilerFiles:
.sif
Stationary Image File, basically pictures.
.aif
Animated Image File, basically animated pictures (gifs).
.exf
Executable File, basically .exe.
.txt
Text file.

Just in case, the monitor is:
/\
|| 19 pixels high
\/
<=> 51 pixels long

Pastebin url (better):
http://pastebin.com/qTMxfGGU
Full code:
Spoiler

sizes = {"","k","M","G","T"}
shell.run("clear")
path = "/"
scroll = 0
while true do
shell.run("clear")
files = fs.list(path)
if #files > 16+scroll then
  tmpf = 17
else
  tmpf = #files
end
for i=1, tmpf do
  if fs.isDir(path..files[i+scroll]) then
   term.setTextColor(colors.yellow)
   print(files[i+scroll])
  else
   if string.len(files[i+scroll]) > 4 then
	tmp3 = string.sub(files[i+scroll], #files[i+scroll]-3, #files[i+scroll])
	if tmp3 == ".sif" then
	 term.setTextColor(colors.lime)
	elseif tmp3 == ".aif" then
	 term.setTextColor(colors.orange)
	elseif tmp3 == ".exf" then
	 term.setTextColor(colors.lightBlue)
	elseif tmp3 == ".txt" then
	 term.setTextColor(colors.lightGray)
	else
	 term.setTextColor(colors.white)
	end
   else
	term.setTextColor(colors.white)
   end
   temp = fs.getSize(path..files[i+scroll])
   tmp = 1
   while temp >= 1024 do
	temp = math.floor(temp/102,4)/10
	tmp = tmp+1
   end
   if string.len(files[i+scroll]) > 4 then
	if string.sub(files[i+scroll], string.len(files[i+scroll])-3, string.len(files[i+scroll])-3) == "." then
	 print(string.sub(files[i+scroll]), 1, string.len(files[i+scroll])-4.."  ["..temp..sizes[tmp].."b]")
	else
	 print(files[i+scroll].."  ["..temp..sizes[tmp].."b]")
	end
   else
	print(files[i+scroll].."  ["..temp..sizes[tmp].."b]")
   end
  end
end
term.setCursorPos(1,18)
term.setTextColor(colors.red)
print("Path: "..path)
term.setCursorPos(1, 19)
if path ~= "/" then
  term.setTextColor(colors.yellow)
  write("..")
else
  write("Exit")
end
event = nil
while event ~= "mouse_click" and event ~= "mouse_scroll" do
  event, param, x, y = os.pullEvent()
end
if event == "mouse_click" and param == 1 then
  if y <= tmpf then
   tmp3 = nil
   if string.len(files[y+scroll]) > 4 then
	tmp3 = string.sub(files[y+scroll], #files[y+scroll]-3, #files[y+scroll])
   end
   if fs.isDir(path..files[y+scroll]) then
	path = path..files[y+scroll].."/"
	scroll = 0
   elseif tmp3 == ".sif" then
	shell.run("picturer.exf", path..files[y+scroll])
   elseif tmp3 == ".exf" then
	shell.run(path..files[y+scroll])
   elseif tmp3 == ".txt" then
	shell.run("preview", path..files[y+scroll])
   end
  elseif y == 19 then
   if path ~= "/" then
	tmp2 = string.sub(path, 1, string.len(path)-1)
	while string.sub(tmp2, string.len(tmp2), string.len(tmp2)) ~= "/" do
	 tmp2 = string.sub(tmp2, 1, string.len(tmp2)-1)
	end
	path = tmp2
	scroll = 0
   else
	shell.run("clear")
	return
   end
  end
elseif event == "mouse_click" and param == 2 then
  if files[y+scroll] ~= nil then
   term.setCursorPos(41, y)
   term.setTextColor(colors.green)
   write("DELETE:EDIT")
   event2, param2, x2, y2 = os.pullEvent("mouse_click")
   if x2>=41 and x2<=46 and y2==y and (not fs.isReadOnly(path..files[y+scroll])) then
	fs.delete(path..files[y+scroll])
   elseif x2>=48 and x2<=51 and y2==y and (not fs.isDir(path..files[y+scroll])) then
	tmp3 = nil
	if string.len(files[y+scroll]) > 4 then
	 tmp3 = string.sub(files[y+scroll], #files[y+scroll]-3, #files[y+scroll])
	end
	if tmp3 == ".sif" then
	 shell.run("picturer.exf", path..files[y+scroll], "edit")
	else
	 shell.run("edit", path..files[y+scroll])
	end
   end
  else
   term.setCursorPos(33, y)
   term.setTextColor(colors.green)
   write("NEW FILE:NEW FOLDER")
   event2, param2, x2, y2 = os.pullEvent("mouse_click")
   if x2>=33 and x2<=43 and y2==y then
	term.setCursorPos(1, y)
	c = fs.open(path..read(), "a")
	c.close()
   elseif x2>=45 and x2<=51 and y2==y then
	term.setCursorPos(1, y)
	fs.makeDir(path..read())
   end
  end
elseif param == 1 and scroll < #files-17 then
  scroll = scroll+1
elseif param == -1 and scroll > 0 then
  scroll = scroll-1
end
end
johnnic #2
Posted 07 September 2013 - 11:49 AM
What multiple points means is you had a variable that was like this:

someVariable=1.0.25
That should have been like:

someVariable="1.0.25"
That happens because lua tries to read the first example as a number, and it does not satisfy what it knows about numbers,
Ziriee #3
Posted 07 September 2013 - 11:58 AM
What multiple points means is you had a variable that was like this:

someVariable=1.0.25
That should have been like:

someVariable="1.0.25"
That happens because lua tries to read the first example as a number, and it does not satisfy what it knows about numbers,

Kinda fixed it, actually it was:

print(string.sub(files[i+scroll]), 1, string.len(files[i+scroll])-4 .."  ["..temp..sizes[tmp].."b]")
I added a space between the '4' and '..'

BTW, now I get "browser.exf:42: bad argument: number expected, got nil"
EDIT: Fixed it! It was a problem with brackets