Posted 06 June 2013 - 10:57 AM
I recently tried using this code from KaoS to make a scrolling list of the members of my server and their roles but when trying to reformat the code so it is easier to add new people I ran into a little problem with tables. I know that it is the tables that are causing the problem but I cannot figure out how to keep the program scrolling correctly while using tables. Thank you in advance to anyone who helps me out with this issue.
Here is the error that I am receiving
My programs code
KaoS's original code
Here is the error that I am receiving
1:37: bad arguement: string expected, got table
My programs code
Spoiler
-- Config --
monSide = "right" -- Side the monitor is on relative to the computer --
title = "-- DirePlayers --" -- Title of the list --
opstitle = "-- DireOP's --" -- OP's Title --
adminstitle = "-- DireAdmins --" -- Admins Title --
playerstitle = "-- DireMembers --" -- Players Title --
ops = {
"Zatharus28",
"MoparDan"
}
admins = {
"Drega1642",
"Tikaran"
}
players = {
"RustikGaming",
"Wolfpax181",
"AnotherPlatypus",
"Desexeh",
"Kibakichi",
"MaliceRoyal",
"RyuMarksmen",
"SoulLion",
"Malsvir_Sjach",
"TutorMC"
}
-- Code --
mon = peripheral.wrap(monSide)
term.redirect( mon )
local function pcenter(input)
local size={term.getSize()}
local pos={term.getCursorPos()}
if input then
term.setCursorPos(size[1]/2-string.len(input)/2,pos[2])
write(input)
end
end
local function scrollat(input,starty,endy,delay)
if not input then
term.clear()
term.setCursorPos(1,1)
print("USAGE: scrollat(table-of-scrolling-values,y-value-at-which-the-nest-starts,y-value-at-which-the-nest-stops,the-time-in-seconds-between-each-scroll)")
end
if type(input)~="table" then
print("incorrect input")
return nil
end
delay=delay or 1
local scrolled=0
while true do
for y=starty,endy do
term.setCursorPos(1,y)
local current=y+scrolled-starty+1
if current>#input then
current=current-#input
end
local size={term.getSize()}
for a=1,size[1]-1 do
write(" ")
end
pcenter(input[current])
end
scrolled=scrolled+1
if scrolled>#input then
scrolled=1
end
sleep(delay)
end
end
local tBanned = {opstitle,ops," ",adminstitle,admins," ",playerstitle,players," "}
term.clear()
term.setCursorPos(1,1)
pcenter(title)
local size={term.getSize()}
scrollat(tBanned,3,size[2]-1,1)
KaoS's original code
Spoiler
local function pcenter(input)
local size={term.getSize()}
local pos={term.getCursorPos()}
if input then
term.setCursorPos(size[1]/2-string.len(input)/2,pos[2])
write(input)
else
print("oops")
print(pos[2])
print(input)
end
end
local function scrollat(input,starty,endy,delay)
if not input then
term.clear()
term.setCursorPos(1,1)
print("USAGE: scrollat(table-of-scrolling-values,y-value-at-which-the-nest-starts,y-value-at-which-the-nest-stops,the-time-in-seconds-between-each-scroll)")
end
if type(input)~="table" then
print("incorrect input")
return nil
end
delay=delay or 1
local scrolled=0
while true do
for y=starty,endy do
term.setCursorPos(1,y)
local current=y+scrolled-starty+1
if current>#input then
current=current-#input
end
local size={term.getSize()}
for a=1,size[1]-1 do
write(" ")
end
pcenter(input[current])
end
scrolled=scrolled+1
if scrolled>#input then
scrolled=1
end
sleep(delay)
end
end
local tBanned = {"Hyper Kinetic Lens", "Red Matter Furnace", "Volcanite Amulet", "Black Hole Chest", "Mercurial Eye", "Black Hole Band", "Watch of Flowing Time", "Evertide Amulet", "Nova Catalyst", "Wireless Tracker", "Destruction Catalyst", "Wireless Transceiver", "Wireless Sniffer", "Wireless Remote", "Wireless Map", "World Anchor", "Rings Of Arcana", "Nova Cataclysm", "Gem Armor", "Void Ring", "Nukes, TNT, ITNT, Dynamite, Sticky Dynamite", "Alchemical Tome", "DarkMatter Pedestal", "Teleport Tether", "REP", "Mining Laser", "Crafting Bench 3", "All Energy Collectors", "Gas Jetpacks", "Block Breaker", "Terraformer", "Alarms", "RM Tools", "DM Tools", "Philosopher's Stone"}
term.clear()
term.setCursorPos(1,1)
pcenter("--PERMANENT BANNER--")
local size={term.getSize()}
scrollat(tBanned,3,size[2]-1,1)