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

Something isn't displaying right - custom file explorer

Started by crazyadam0, 07 April 2014 - 10:11 PM
crazyadam0 #1
Posted 08 April 2014 - 12:11 AM
I am making a custom file explorer for an operating system and things are not working right. it displays hidden folders and normal files but wont display normal folders or hidden files. Can someone please tell me why this is. It happened after I gave it the ability to see if a file/folder was hidden or not. I probably made a silly mistake somewhere. It uses a simple API called draw though because it will already be loaded when the custom os boots. To run this program you will have to download the api, name it draw, and use the lua console to load it. then run the program.

Main Program: http://pastebin.com/RUfv5BV7
Draw API: http://pastebin.com/DE92Ks9j
Edited on 08 April 2014 - 11:15 PM
Thefdjurt #2
Posted 08 April 2014 - 07:35 AM
First off, semicolons ";" are completely unnecessary.
I, as of now, haven't even tested the code, so my following remarks are based of a quick glance at the code (my post will be updated after I do test the code however). Anyways… here is what I believe could solve some problems:

In your categorization you should have something along the lines of

if fs.isDir(path.."/"..temp) then
  if string.sub(temp, 1, 1) == "." then
    hDirList[#hDirList + 1] = temp
  else
    dirList[#dirList + 1] = temp
  end
else
  if string.sub(temp, 1, 1) == "." then
    hFileList[#hFileList + 1] = temp
  else
    fileList[#fileList + 1] = temp
  end
end
Also
 path = tArgs[1] or "/" 
should be
 path = tArgs[1] or "" 

And if you are getting any error messages, posting them is important for fixing the code.
EDIT: I realize now that setting the path to an empty string will cause errors later on
Edited on 08 April 2014 - 10:19 AM
CometWolf #3
Posted 08 April 2014 - 10:53 AM
Your second point, while true performance wise, has no bearing on the issue. Your third point has no bearing at all. Passing an empty string as the path might even cause an error.

As for the actual issue, i suspect the following

lastY = lastY+i
Since i will increase by one for every loop, you are effectivly adding 1, then 2, then 3 and so on. This could quickly throw the cursor offscreen. Im guessing it should be 1 instead.
Edited on 08 April 2014 - 09:08 AM
crazyadam0 #4
Posted 09 April 2014 - 12:25 AM
Your second point, while true performance wise, has no bearing on the issue. Your third point has no bearing at all. Passing an empty string as the path might even cause an error.

As for the actual issue, i suspect the following

lastY = lastY+i
Since i will increase by one for every loop, you are effectively adding 1, then 2, then 3 and so on. This could quickly throw the cursor offscreen. Im guessing it should be 1 instead.


Thanks for the help I didn't realize I was adding to lastY with every iteration. After I fixed that it worked.

And Convo_Bomber thanks for the logic tip I will use that because it looks prettier to me for some reason.

EDIT: I know semicolons are unnecessary I just do it out of habit because I come from C# and Java
Edited on 08 April 2014 - 10:27 PM