This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
RustikGaming's profile picture

[Lua][Code Error] Help with Tables and Scrolling Text

Started by RustikGaming, 06 June 2013 - 08:57 AM
RustikGaming #1
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

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)
LBPHacker #2
Posted 06 June 2013 - 02:06 PM
"ops", "admins" and "players" are tables. You give them to string.len on line 62, and it begins complaining about that. If you really want to keep the current layout of the program, handle tables properly. Every value of tBanned should be a string. Have this pastebin (NSay2dEG). Solved and cleaned it up a bit.
RustikGaming #3
Posted 07 June 2013 - 09:38 PM
Thanks so much LBP!!!