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

Adding A Banner At The Top Of Scrolling Text That Stays

Started by McBessemer, 11 August 2012 - 09:44 PM
McBessemer #1
Posted 11 August 2012 - 11:44 PM
Hello,
I recently tried to add a timer that would restart the computer after so many seconds but when adding it to my scrolling text program it gives me: "bios:206: [string "Rules"]:52: '=' expected" But I do not see the problem its pointing me to. Also the text that I want to stay at the top while the rest scrolls does not stay. Here is the code:

os.startTimer(75)
print("Banned That Stays At The Top")
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"
}
while true do
for i, sBanned in ipairs(tBanned) do
sleep(1)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sBanned / 2)),0)
term.setCursorPos(x + 1,y)
print(sBanned)
print("--------------------BLOCKED--------------------")
local r = os.pullEvent()
if r == "timer" then
os.reboot
break
end
end
end
Lyqyd #2
Posted 12 August 2012 - 12:20 AM
'os.reboot' should be 'os.reboot()'.
McBessemer #3
Posted 12 August 2012 - 12:45 AM
'os.reboot' should be 'os.reboot()'.
:P/>/> Woops, Thanks. But what about a way for that top banner to stay?
Cranium #4
Posted 12 August 2012 - 12:59 AM

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"
}
function banner()
term.setCursorPos(1,1)
print("Banned That Stays At The Top")
end
function banned()
while true do
for i, sBanned in ipairs(tBanned) do
sleep(1)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sBanned / 2)),0)
term.setCursorPos(x + 1,y)
print(sBanned)
print("--------------------BLOCKED--------------------")
local r = os.pullEvent()
if r == "timer" then
break
end
end
end
end
os.startTimer(75)
parallel.waitForAll(banner,banned)
os.reboot()
I haven't tried it, but I think this might work. It uses the parallel API to constantly print the banner at the top.
Lyqyd #5
Posted 12 August 2012 - 01:02 AM
After each print call in the loop, just have it clear the line, move the cursor to the top, re-write the first line, then move the cursor back down to where it was.


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"
}
function banner()
term.setCursorPos(1,1)
print("Banned That Stays At The Top")
end
function banned()
while true do
for i, sBanned in ipairs(tBanned) do
sleep(1)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sBanned / 2)),0)
term.setCursorPos(x + 1,y)
print(sBanned)
print("--------------------BLOCKED--------------------")
local r = os.pullEvent()
if r == "timer" then
break
end
end
end
end
os.startTimer(75)
parallel.waitForAll(banner,banned)
os.reboot()
I haven't tried it, but I think this might work. It uses the parallel API to constantly print the banner at the top.

The parallel API is kind of overkill for something so simple (and probably wouldn't work anyway).
Cranium #6
Posted 12 August 2012 - 01:25 AM
Yeah, I suppose so, but it was the only way I learned how to keep something going, without calling back to the function millions of times. And like I said, I haven't tried it. Still too hung up on my own code problem…. :P/>/>
McBessemer #7
Posted 12 August 2012 - 01:49 AM
I tryed the parallel API like you suggested (craniumkid22) but it only prints the first thing in the table and then stops. I would try going back up to clear the line and rewrite the the banner and then contine with the loop but I wouldnt know how to get that to work. Here is the attempt at the parallel API:

os.startTimer(75)
local tBanned = {
"Hyper Kinetic Lens",
"Red Matter Furnace",
"Volcanite Amulet",
}
function banner()
term.setCursorPos(1,1)
print("Banner")
end
function banned()
while true do
for i, sBanned in ipairs(tBanned) do
sleep(1)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sBanned / 2)),0)
term.setCursorPos(x + 1,y)
print(sBanned)
print("--------------------BLOCKED--------------------")
if os.pullEvent() == "timer" then
os.reboot()
break
end
end
end
end
parallel.waitForAll(banner,banned)
Cranium #8
Posted 12 August 2012 - 02:06 AM
Are you wanting this to print a list continually, and have it say blocked under it, one line at a time? Or do you want that list to scroll?
McBessemer #9
Posted 12 August 2012 - 02:11 AM
I wanted it so that it could just say "Blocked Blocsk and Items" at the top and have it stay as all the items in the table scroll up. The timer is there to reboot the computer so the the music disk would restart. The —-Blocked— was just a temp fix as it should just be ————– under each item/block listen to seperate them.
Cranium #10
Posted 12 August 2012 - 02:57 AM
Well, I got it to do your scrolling, but I ran into another problem where the options disappear after the first few display. Perhaps the experts can finish where I failed.

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"
}
function banner()
while true do
term.setCursorPos(1,1)
term.clearLine()
print("Your Awesome Banner!")
sleep(0)
end
end
function banned()
term.clear()
local y = 2
local w, h = term.getSize()
while true do
for i, sBanned in ipairs(tBanned) do
sleep(1)
b = string.len(tBanned[i])/2
x = (w/2)-b
term.setCursorPos(x,y + 1)
print(sBanned)
print("---------------------BLOCKED---------------------")
y = y + 2
end
end
end
function timer()
local r = os.pullEvent()
if r == "timer" then
end
end
os.startTimer(75)
parallel.waitForAll(banner,banned,timer)
os.reboot()
Lyqyd #11
Posted 12 August 2012 - 05:54 AM
Did you still want the hyphens-blocked-hyphens line? This should continuously scroll the banned list while keeping the title at the top.


while true do
	for i, sBanned in ipairs(tBanned) do
		sleep(1)
		local w, h = term.getSize()
		local x, y = term.getCursorPos()
		x = math.max(math.floor((w / 2) - (#sBanned / 2)),0)
		term.setCursorPos(x + 1,y)
		print(sBanned)
		local tx, ty = term.getCursorPos()
		term.setCursorPos(1, 1)
		term.clearLine()
		term.write("Banner At The Top, Yo.")
		term.setCursorPos(tx, ty)
	end
end
McBessemer #12
Posted 12 August 2012 - 03:53 PM
Okay so that worked for the banner and list but it stops when it hits the timer part. Here is the code:

[size=3]os.startTimer(75)
local tBanned = {
"Hyper Kinetic Lens",
"Red Matter Furnace",
"Volcanite Amulet",
}
while true do
for i, sBanned in ipairs(tBanned) do
sleep(1)
local w, h = term.getSize()
local x, y = term.getCursorPos()
x = math.max(math.floor((w / 2) - (#sBanned / 2)),0)
term.setCursorPos(x + 1,y - 1)
print(sBanned)
print("-----------------------------------------------")
local tx, ty = term.getCursorPos()
term.setCursorPos(5, 1)
term.clearLine()
term.write("Banner At The Top, Yo.")
term.setCursorPos(tx, ty)
if os.pullEvent() == "timer" then
os.reboot()
break
end
end
end
Lyqyd #13
Posted 12 August 2012 - 05:37 PM
Why does it need to reboot every 75 seconds, by the way? If you just take that part out, it should work fine.
Cranium #14
Posted 12 August 2012 - 05:48 PM
He said that it's so it would restart a music player.
McBessemer #15
Posted 12 August 2012 - 07:53 PM
I have it setup in the startup script to start the music disk in the disk drive then run the scrolling program. I wanted to restart the computer every 75 seconds to refresh the music disk so it starts again.
Noodle #16
Posted 12 August 2012 - 07:57 PM
More efficient would be just to draw both places.. Reload the banner after you scroll..
cant_delete_account #17
Posted 12 August 2012 - 08:41 PM
I have it setup in the startup script to start the music disk in the disk drive then run the scrolling program. I wanted to restart the computer every 75 seconds to refresh the music disk so it starts again.
Instead of restarting you could implement some code at the top like disk.startAudio(sideofdiskdrive) and then to restart it disk.stopAudio(sideofdiskdrive) then disk.startAudio(sideofdiskdrive) (those might not be the right functions names, but there's something like that)
McBessemer #18
Posted 12 August 2012 - 10:15 PM
But the problem is still there, there is still no way to implament that with the timer to go back an issue the disk.startAudio.
McBessemer #19
Posted 13 August 2012 - 06:30 PM
I've tryed all attempts at using the parellel API and setting the timer up with this but I still cant get it to work… If I really wanted it would it require me to rewrite the whole code?
Lyqyd #20
Posted 14 August 2012 - 01:03 AM
Nope, just use two timers. One for one second, one for the seventy-five. Pull the event, check which timer it is, act appropriately.
KaoS #21
Posted 15 August 2012 - 02:18 PM
why are we even using the parallel api to loop creating the top banner, just place the banner there and never write to that position



local function pcenter(input)
size={term.getSize()}
pos={term.getCursorPos()}
term.setCursorpos(size[1]/2-string.len(input)/2,pos[2])
write(input)
end

local function scrollat(input,starty,endy,delay)
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)
pcenter(input[y+scrolled])
end
scrolled=scrolled+1
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.setCursorPos(1,1)
pcenter("--PERMANENT BANNER--")
scrollat(tBanned,3,10)

try that, it should scroll between lines 3 and 10 (this can be changed easily), as I am at work I cannot test (many apologies) but I am sure you are capable of troubleshooting any stupid mistakes I made, this is how I would do it

PS any mistakes are most likely in the center print
KaoS #22
Posted 15 August 2012 - 02:24 PM
sorry, in the scrollat function replace

pcenter(input[y+scrolled])
with

pcenter("	 "..input[y+scrolled.."	 "])

so it clears any remains from the previous string as well or just make it write a full line of spaces and then the next string or it won't work correctly on varying length items
Cranium #23
Posted 15 August 2012 - 02:27 PM
why are we even using the parallel api to loop creating the top banner, just place the banner there and never write to that position
The problem with not using the parallel, is that I think he wants it to scroll through the list indefinitely, and it's too long of a list to fit on the terminal, so it would automatically push that line up when it gets too full.
KaoS #24
Posted 15 August 2012 - 03:07 PM
yes, true but read my posted code, it is a nested scroller
Cranium #25
Posted 15 August 2012 - 03:12 PM
Ah, did not see that.
KaoS #26
Posted 15 August 2012 - 03:22 PM
I have corrected 3 problems in the code, here we have it

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)

It is tested now and scrolls to the bottom