Jump to content




Help with basic OS browser


  • You cannot reply to this topic
10 replies to this topic

#1 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 29 August 2012 - 12:50 PM

Hey everyone, I have just started working on a basic OS system which I want to develop but I have hit a roadblock, the function that builds a list of all files and directories gives an error when I try to enter a second directory, here is the code (a little messy as I just started earlier today while busy on other things, apologies)

The program code:
Spoiler

the menu api that I developed and use in it:
Spoiler

It returns
53: index expected, got nil

any help would be greatly appreciated (just please don't tell me to steal redworks code. this is about building it myself so I can add handles for additional uses and functionality)

EDIT: I successfully open files and folders but when I try to open rom/anydirectory it crashes :)/>

#2 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 29 August 2012 - 02:40 PM

View PostKaoS, on 29 August 2012 - 12:50 PM, said:

Hey everyone, I have just started working on a basic OS system which I want to develop but I have hit a roadblock, the function that builds a list of all files and directories gives an error when I try to enter a second directory, here is the code (a little messy as I just started earlier today while busy on other things, apologies)

The program code:
Spoiler

the menu api that I developed and use in it:
Spoiler

It returns
53: index expected, got nil

any help would be greatly appreciated (just please don't tell me to steal redworks code. this is about building it myself so I can add handles for additional uses and functionality)

EDIT: I successfully open files and folders but when I try to open rom/anydirectory it crashes :)/>
the rom folders are write protected check if you are just looking for content and not trying to edit something, also take a look at the ls or dir programm

#3 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 29 August 2012 - 02:43 PM

that is what I modelled it after, it just uses the fs.list command and shell.dir command, nothing trying to write to anything

#4 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 29 August 2012 - 03:11 PM

hmm that's odd

#5 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 30 August 2012 - 06:29 AM

yeah tell me about it, I am at a loss because you can browse through any number of directories but not into a rom subfolder

#6 BigSHinyToys

  • Members
  • 1,001 posts

Posted 30 August 2012 - 06:41 AM

I don't know if this will be of help but here is a File Browser I made and it works with folder in ROM.
http://pastebin.com/9itmSeyA

It can only launch programs and is not complete.

#7 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 30 August 2012 - 06:48 AM

wait a sec, I just realised this is probably not CC, I am using the emulator from these forums, maybe that is why it does not work

EDIT: and @BigSHinyToys: wow, nice code. I find it hard to manage such a large code and keep it organised, I would also recommend making barrier a function that recalculates the width and height of the screen each time etc so they can change screen size and it would still work, there are a few things I would change but I guess it's mainly just preference, great code dude

#8 BigSHinyToys

  • Members
  • 1,001 posts

Posted 30 August 2012 - 07:27 AM

line 53 causes that error because there in no table in the main table at that position.

I have added a fix but other errors are still there. see if you can track them down
http://pastebin.com/dsCJrU2E

#9 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 30 August 2012 - 07:34 AM

what do you mean? if that is the problem then the if statement should catch it

#10 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 30 August 2012 - 07:57 AM

I finally found the error on line 50, it now works fine

local function count(input)
if type(input)~="table" then
  print("incorrect input: "..tostring(input))
  return
end
local int=0
for a in pairs(input) do
  int=int+1
end
return int
end
local function combinet(one,two)
if type(one)~="table" or type(two)~="table" then
  print("incorrect input")
  return
end
for k,v in pairs(two) do
  if type(k)=="number" then
   one[count(one)+1]=v
  else
   one[k]=v
  end
end
return one
end
function check(input)
if not fs.isDir(shell.resolve(input)) then
  return menu.alternate({{'edit', 'run'}},{{{shell.run,"edit",input},{shell.run,input}}})
end
end
while true do
local currentdirs={{}}
local currentfiles={{}}
local cds={{}}
local acts={{}}
for k,v in pairs(fs.list(shell.dir())) do
  if fs.isDir(shell.resolve(v)) then
   if count(currentdirs[count(currentdirs)])==3 then
	currentdirs[count(currentdirs)+1]={}
	cds[count(currentdirs)+1]={}
   end
   currentdirs[count(currentdirs)][count(currentdirs[count(currentdirs)])+1]=v
   cds[count(currentdirs)][count(currentdirs[count(currentdirs)])]={shell.setDir,shell.resolve(v)}
  else
   if count(currentfiles[count(currentfiles)])==3 then
	currentfiles[count(currentfiles)+1]={}
	acts[count(currentfiles)]={}
   end
   currentfiles[count(currentfiles)][count(currentfiles[count(currentfiles)])+1]=v
   acts[count(currentfiles)][count(currentfiles[count(currentfiles)])]={check,v}
  end
end
for k,v in pairs(currentfiles) do
  currentdirs[count(currentdirs)+1]=v
end
for k,v in pairs(acts) do
  cds[count(cds)+1]=v
end
menu.alternate(currentdirs,cds)
end

now I just need to add functionality for if there are no directories or files

#11 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 30 August 2012 - 08:54 AM

And here is the final result:

Spoiler

with menu function
Spoiler

EDIT: updated

Edited by KaoS, 30 August 2012 - 11:54 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users