chest = peripheral.wrap("back") dir = "EAST" chest.pullItem(dir,1) sleep(1) local numBooks = #chest.getAllStacks() print("Portal Randomizer") print("-----------------") print("Number of Locations: " .. numBooks) local useSlot = 1 function showInfo() local powered = rs.getInput("top") refreshLine("Powered: " .. tostring(powered),7) if powered then refreshLine("Using: " .. useSlot,8) end end function refreshLine(t,l) term.setCursorPos(1,l) term.clearLine() term.setCursorPos(1,l) term.write(t) end while true do if rs.getInput("top") then useSlot = math.random(numBooks) showInfo() chest.pushItem(dir,useSlot) sleep(1) chest.pullItem(dir,1) else showInfo() sleep(1) end end