Currently I am setting up a sorting system and it's going swimmingly. However, I've had a slight blockade in the way that I wanted to setup the terminal menu to view stored items.
I'm currently using this nitty-gritty bit of code to pull the directory of "Items" and display every item in the folder as a scrollable list.
list = fs.list("Items/")
for i,v in ipairs(list) do
--i being the iterator, v being the value
print(v) --print value
end
--OR
list = fs.list("Items/")
for i = 1,#list do
print(list[i])
end
local scrollBuffer = {}
local _,maxY = term.getSize()
for k, v in pairs(list) do
print(k .. " : " .. v)
table.insert(scrollBuffer,k.." : ".. v)
end
local y = #scrollBuffer
while true do
local _, direction = os.pullEvent("mouse_scroll")
if direction == 1 then --# direction 1 is when you scroll the wheel one way
if y < #scrollBuffer-maxY then
y=y+1
end
term.clear()
term.setCursorPos(1,1)
for i = 1, maxY-1 do
if not scrollBuffer[i+y] then break end
print(scrollBuffer[i+y])
end
term.write(scrollBuffer[maxY+y])
elseif direction == -1 then --# -1 is the only direction
if y~=0 then --# not going to explain anymore, as it all repeats from here
y=y-1
end
term.clear()
term.setCursorPos(1,1)
for i = 1, maxY-1 do
if not scrollBuffer[i+y] then break end
print(scrollBuffer[i+y])
end
term.write(scrollBuffer[maxY+y])
end
end
This works well, the problem I am experiencing is adding the ability to click on individual items. From past experiences with "os.pullEventRaw("mouse_click")" I used coordinates to define clickability but I don't know how to approach this list doodad.Any help is appreciated.