edit file to clean this
This commit is contained in:
@ -1,24 +1,51 @@
|
||||
-- ask direction to get methods of a peripheral
|
||||
print("Enter the direction of the peripheral (left, right, top, bottom, front, back):")
|
||||
local direction = io.read()
|
||||
if not direction or direction == "quit" or direction == "exit" then
|
||||
local function getPeripheralDirection()
|
||||
print("Enter the direction of the peripheral (left, right, top, bottom, front, back):")
|
||||
local direction = io.read()
|
||||
if not direction or direction == "quit" or direction == "exit" then
|
||||
print("No direction specified, exiting.")
|
||||
return
|
||||
end
|
||||
return direction
|
||||
end
|
||||
|
||||
local function checkDirectionIsValid(direction)
|
||||
if not direction or direction == "quit" or direction == "exit" then
|
||||
print("No direction specified, exiting.")
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function getMethodsPeripheral(direction)
|
||||
local info = peripheral.getMethods(direction)
|
||||
return info
|
||||
end
|
||||
|
||||
local function displayMethodsPeripheral(info)
|
||||
local nbOfMethods = 0
|
||||
for methodName, methodInfo in pairs(info) do
|
||||
nbOfMethods = nbOfMethods + 1
|
||||
if nbOfMethods > 10 then
|
||||
print("Too many methods, please press a key to continue...")
|
||||
event, p1 = os.pullEvent("key")
|
||||
nbOfMethods = 0
|
||||
term.clear()
|
||||
end
|
||||
print(methodName .. ' ' .. methodInfo)
|
||||
end
|
||||
end
|
||||
|
||||
-- main
|
||||
local direction = getPeripheralDirection()
|
||||
local isDirectionIsNotEmpty = checkDirectionIsValid(direction)
|
||||
if not isDirectionIsNotEmpty then
|
||||
print("No direction specified, exiting.")
|
||||
return
|
||||
end
|
||||
local info = {}
|
||||
|
||||
info = peripheral.getMethods(direction)
|
||||
|
||||
-- list the methods from info
|
||||
|
||||
local nbOfMethods = 0
|
||||
for methodName, methodInfo in pairs(info) do
|
||||
nbOfMethods = nbOfMethods + 1
|
||||
if nbOfMethods > 10 then
|
||||
print("Too many methods, please press a key to continue...")
|
||||
event, p1 = os.pullEvent("key")
|
||||
nbOfMethods = 0
|
||||
term.clear()
|
||||
end
|
||||
print(methodName .. ' ' .. methodInfo)
|
||||
local info = getMethodsPeripheral(direction)
|
||||
if not info then
|
||||
print("No info found, exiting.")
|
||||
return
|
||||
end
|
||||
|
||||
displayMethodsPeripheral(info)
|
||||
|
||||
Reference in New Issue
Block a user