The program code:
Spoiler
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)+1]={}
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
for k,v in pairs(currentdirs) do
for a,b in pairs(v) do
print(k.." "..a.." "..B)/>/>
end
end
menu.alternate(currentdirs,cds)
end
the menu api that I developed and use in it:
Spoiler
function generate(choices, results, spacing)
spacing=tonumber(spacing) or 7
if type(choices)~="table" or type(results)~="table" then
print("ERROR GENERATING MENUnINPUT INCORRECT")
return nil
end
local selectedx=1
local selectedy=1
while true do
term.clear()
for y=1,#choices do
for x=1,#choices[y] do
if x==selectedx and y==selectedy then
term.setCursorPos(x*spacing-spacing+1,y)
write(">"..choices[y][x].."<")
else
term.setCursorPos(x*spacing-spacing+2,y)
write(choices[y][x])
end
end
end
print("")
while true do
local event,param1=os.pullEvent("key")
if param1==203 and selectedx>1 then
selectedx=selectedx-1
break
end
if param1==205 and selectedx<#choices[selectedy] then
selectedx=selectedx+1
break
end
if param1==200 and selectedy>1 then
selectedy=selectedy-1
break
end
if param1==208 and selectedy<#choices then
selectedy=selectedy+1
break
end
if param1==28 then
return loadstring(results[selectedy][selectedx])()
end
end
if selectedx>#choices[selectedy] then
selectedx=#choices[selectedy]
end
end
end
function alternate(choices, results, spacing)
spacing=tonumber(spacing) or 7
if type(choices)~="table" or type(results)~="table" then
print("ERROR GENERATING MENUnINPUT INCORRECT")
return nil
end
local selectedx=1
local selectedy=1
while true do
term.clear()
for y=1,#choices do
for x=1,#choices[y] do
if x==selectedx and y==selectedy then
term.setCursorPos(x*spacing-spacing+1,y)
write(">"..choices[y][x].."<")
else
term.setCursorPos(x*spacing-spacing+2,y)
write(choices[y][x])
end
end
end
print("")
while true do
local event,param1=os.pullEvent("key")
if param1==203 and selectedx>1 then
selectedx=selectedx-1
break
end
if param1==205 and selectedx<#choices[selectedy] then
selectedx=selectedx+1
break
end
if param1==200 and selectedy>1 then
selectedy=selectedy-1
break
end
if param1==208 and selectedy<#choices then
selectedy=selectedy+1
break
end
if param1==28 then
if results[selectedy][selectedx][3] then
return results[selectedy][selectedx][1](results[selectedy][selectedx][2],results[selectedy][selectedx][3])
else
return results[selectedy][selectedx][1](results[selectedy][selectedx][2])
end
end
end
if selectedx>#choices[selectedy] then
selectedx=#choices[selectedy]
end
end
end
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 :)/>/>