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

help

Started by ShadowCreeper559, 04 March 2014 - 05:45 PM
ShadowCreeper559 #1
Posted 04 March 2014 - 06:45 PM
ok i have bean trying to get this code to scroll vertically all day and cant i have removed all my misstates so the code at this point just prints to the monitor plz help

local rules = {
"&eNOTICE. The use of external tools, scripts or other vote boosting methods are prohibited.\n&0",
"\n",
"&3RULE 1.0&0. No Harassment, Bullying or Disrespect to anyone on the server including Staff, other Players and Guests. This also extends to the forum; this includes swearing directly at someone ingame, or harassing other players because of something you do not like. \n",
"\n\n",
"&3RULE 1.1&0. We're not stupid, we can see when you are duping.\n",
"\n\n",
"&3RULE 1.2&0. This rule is simple, PVP is disabled then do not try and kill another player. This includes placing turrets (for example next to another players land), placing lava, water, gravel or sand on another player while they are AFK, and traps. We classify any of these methods of cheating, and punishments are harsh.\n",
"\n\n",
"&3RULE 1.3&0. If an item is on the banned or restricted list and you do not have explicit permission from an administrator (only) to use/craft/place/interact with the item, you could be jailed/banned for breaking this rule if caught with the item.\n",
"\n\n",
"&3RULE 1.4&0. We don't allow griefing or stealing anywhere within the main world. You may steal from a non-residence within The Nether, The Twilight Forest and The End, you may not grief these worlds, i.e destroying blocks for the sake of destruction, revenge or otherwise. You may NOT grief or steal within a residence in any world, even if you have trusted permissions within the residence, including the 3 listed before.\n",
"\n\n",
"&3RULE 1.5&0. We will not accept any form of advertising in game for things unrelated to this server. This includes, but is not limited to advertising other servers, websites, youtube channels, facebook pages and other similar things. You may however advertise things within the game, for example you can tell others about your shop or residence, you may not spam the chat or message system.\n",
"\n\n",
"&3RULE 1.6&0. We utilise plugins to prevent players spamming with repeated messages, commands within their messages on the server. If you work out a way to bypass this and spam the chat, you will be mute/jailed/banned.\n",
"\n\n",
"&3RULE 1.7&0. If you are offline, your machines must also be offline. This means when you log off, turn off or disable your machines, we will jail/ban people who breach this rule. Timers are not allowed under 3 seconds, this is to prevent lag.\n",
"\n\n",
"&3RULE 1.8&0. You may not protect shared land or blocks. For example, creating a residence within areas like the spawn, or other peoples houses."
}

local function writeWithFormat(…)
local s = "&0"
for k, v in ipairs(arg) do
s = s .. v
end
s = s .. "&0"
local fields = {}
local lastcolor, lastpos = "0", 0
for pos, clr in s:gmatch"()&(%x)" do
table.insert(fields, {s:sub(lastpos + 2, pos - 1), lastcolor})
lastcolor, lastpos = clr , pos
end
for i = 2, #fields do
term.setTextColor(2 ^ (tonumber(fields[2], 16))) write(fields[1])
end
end

local mon = peripheral.wrap("back")
term.redirect(mon)
mon.setTextScale(1.0)

term.clear()
term.setCursorPos(1, 1)

for i = 1, #rules do
writeWithFormat(rules)
end

term.restore()
CometWolf #2
Posted 04 March 2014 - 08:46 PM
Ugh, read THIS.

Now, for my own and other's sanity's sake, imma add the code tags myself before i take a look at it…

local rules = {
"&eNOTICE. The use of external tools, scripts or other vote boosting methods are prohibited.\n&0",
"\n",
"&3RULE 1.0&0. No Harassment, Bullying or Disrespect to anyone on the server including Staff, other Players and Guests. This also extends to the forum; this includes swearing directly at someone ingame, or harassing other players because of something you do not like. \n",
"\n\n",
"&3RULE 1.1&0. We're not stupid, we can see when you are duping.\n",
"\n\n",
"&3RULE 1.2&0. This rule is simple, PVP is disabled then do not try and kill another player. This includes placing turrets (for example next to another players land), placing lava, water, gravel or sand on another player while they are AFK, and traps. We classify any of these methods of cheating, and punishments are harsh.\n",
"\n\n",
"&3RULE 1.3&0. If an item is on the banned or restricted list and you do not have explicit permission from an administrator (only) to use/craft/place/interact with the item, you could be jailed/banned for breaking this rule if caught with the item.\n",
"\n\n",
"&3RULE 1.4&0. We don't allow griefing or stealing anywhere within the main world. You may steal from a non-residence within The Nether, The Twilight Forest and The End, you may not grief these worlds, i.e destroying blocks for the sake of destruction, revenge or otherwise. You may NOT grief or steal within a residence in any world, even if you have trusted permissions within the residence, including the 3 listed before.\n",
"\n\n",
"&3RULE 1.5&0. We will not accept any form of advertising in game for things unrelated to this server. This includes, but is not limited to advertising other servers, websites, youtube channels, facebook pages and other similar things. You may however advertise things within the game, for example you can tell others about your shop or residence, you may not spam the chat or message system.\n",
"\n\n",
"&3RULE 1.6&0. We utilise plugins to prevent players spamming with repeated messages, commands within their messages on the server. If you work out a way to bypass this and spam the chat, you will be mute/jailed/banned.\n",
"\n\n",
"&3RULE 1.7&0. If you are offline, your machines must also be offline. This means when you log off, turn off or disable your machines, we will jail/ban people who breach this rule. Timers are not allowed under 3 seconds, this is to prevent lag.\n",
"\n\n",
"&3RULE 1.8&0. You may not protect shared land or blocks. For example, creating a residence within areas like the spawn, or other peoples houses."
}
local function writeWithFormat(...)
local s = "&0"
for k, v in ipairs(arg) do
s = s .. v
end
s = s .. "&0"
local fields = {}
local lastcolor, lastpos = "0", 0
for pos, clr in s:gmatch"()&(%x)" do
table.insert(fields, {s:sub(lastpos + 2, pos - 1), lastcolor})
lastcolor, lastpos = clr , pos
end
for i = 2, #fields do
term.setTextColor(2 ^ (tonumber(fields[i][2], 16))) write(fields[i][1])
end
end
local mon = peripheral.wrap("back")
term.redirect(mon)
mon.setTextScale(1.0)
term.clear()
term.setCursorPos(1, 1)
for i = 1, #rules do
writeWithFormat(rules[i])
end
term.restore()

Vertical scrolling is actually very simple, since you can place the cursor offscreen.

function vertScroll(text)
  local termX,termY = term.getSize()
  local cursX,cursY = term.getCursorPos()
  local scrollLength = termX-cursX+1 -- calculate visible area
  for i = 1,#text+scrollLength do --loop the length of the text and the length of the visible area
	term.setCursorPos(cursX-#text+i-1,cursY)
	term.write(text)
	sleep(0.2) --scroll speed
  end
end

Working your color scheme into that however is gonna be a bit more complex, i should probably go test this code. gimme a few minutes here.
Edit: I'll add some comments and explainations tomorrow if you want.

function vertScroll(text)
  local termX,termY = term.getSize() -- get terminal size
  local cursX,cursY = term.getCursorPos() --get current cursor position, so it will print to wherever the cursor is currently located
  local scrollLength = termX-cursX+1 -- calculate visible area
  local writeText = string.rep(" ",scrollLength)..text -- pad the text to scroll with enough blank spaces to fill the visible area after the text has scrolled by, to clear it
  for i = 1,#text+scrollLength do --loop the length of the text and the length of the visible area
	term.setCursorPos(cursX-#writeText+i,cursY) --set the cursor offscreen by the length of the string we're scrolling, then subtract how many times we've scroll forward (i)
	local tLines = {} --table containing the strings seperated by color tags, and what color they should be
	for color, line in writeText:gmatch("&(%d)([^&]+)") do -- loop once for every color tag followed by a number (%d) then followed by anything that's not a colortag ([&^]+)
	  tLines[#tLines+1] = {
		string = line, --store the line to the table
		color = color --store the color to the table
	  }
	end
	for i=1,#tLines do --loop once for every entry of the table
	  term.setTextColor(2 ^ tLines[i].color) --set the color
	  term.write(tLines[i].string) --write the text
	end
	sleep(0.2) --pause between each scroll
  end
  term.setCursorPos(cursX,cursY) --return the cursor to it's original position
end

Edited on 05 March 2014 - 09:18 PM
ShadowCreeper559 #3
Posted 05 March 2014 - 09:16 PM
that would be nice thx
CometWolf #4
Posted 05 March 2014 - 10:18 PM
There, hopefully it's understandable :P/> Also i corrected a mistake i realized i made while i was optimizing the code earlier.
ShadowCreeper559 #5
Posted 06 March 2014 - 03:34 PM
can u post the full script so i can copy and past plzz
CometWolf #6
Posted 06 March 2014 - 04:53 PM
That function is all you'll need…. Just redirect to the monitor like you're already doing, then loop your table through that function, like you're already doing.
ShadowCreeper559 #7
Posted 08 March 2014 - 02:50 PM
i cant seam to get it to display the text
theoriginalbit #8
Posted 08 March 2014 - 04:24 PM
you know you could have simply asked the author of the script if he made a scrolling version of it (which he did btw).
Lyqyd #9
Posted 08 March 2014 - 04:24 PM
What have you tried to get it to "display the text"? Does it show any errors when you run the program? What does it do instead of displaying the text?
CometWolf #10
Posted 08 March 2014 - 04:29 PM
Realized i had to do some minor changes, because you're using hex color codes. Also, i had to remove the newline characters, since they just show up as question marks when you use write anyways.
If you really want multiple scrolling lines at the same time, it shoudl be pretty easily doable with the parallel api. I can show you if you need it.

    local rules = {
    "&eNOTICE The use of external tools, scripts or other vote boosting methods are prohibited.",
    "&3RULE 1.0&0. No Harassment, Bullying or Disrespect to anyone on the server including Staff, other Players and Guests. This also extends to the forum; this includes swearing directly at someone ingame, or harassing other players because of something you do not like.",
    "&3RULE 1.1&0. We're not stupid, we can see when you are duping.",
    "&3RULE 1.2&0. This rule is simple, PVP is disabled then do not try and kill another player. This includes placing turrets (for example next to another players land), placing lava, water, gravel or sand on another player while they are AFK, and traps. We classify any of these methods of cheating, and punishments are harsh.",
    "&3RULE 1.3&0. If an item is on the banned or restricted list and you do not have explicit permission from an administrator (only) to use/craft/place/interact with the item, you could be jailed/banned for breaking this rule if caught with the item.",
    "&3RULE 1.4&0. We don't allow griefing or stealing anywhere within the main world. You may steal from a non-residence within The Nether, The Twilight Forest and The End, you may not grief these worlds, i.e destroying blocks for the sake of destruction, revenge or otherwise. You may NOT grief or steal within a residence in any world, even if you have trusted permissions within the residence, including the 3 listed before.",
    "&3RULE 1.5&0. We will not accept any form of advertising in game for things unrelated to this server. This includes, but is not limited to advertising other servers, websites, youtube channels, facebook pages and other similar things. You may however advertise things within the game, for example you can tell others about your shop or residence, you may not spam the chat or message system.",
    "&3RULE 1.6&0. We utilise plugins to prevent players spamming with repeated messages, commands within their messages on the server. If you work out a way to bypass this and spam the chat, you will be mute/jailed/banned.",
    "&3RULE 1.7&0. If you are offline, your machines must also be offline. This means when you log off, turn off or disable your machines, we will jail/ban people who breach this rule. Timers are not allowed under 3 seconds, this is to prevent lag.",
    "&3RULE 1.8&0. You may not protect shared land or blocks. For example, creating a residence within areas like the spawn, or other peoples houses."
    }
    local tHex = {
	  a = 2 ^ 10,
	  b = 2 ^ 11,
	  c = 2 ^ 12,
	  d = 2 ^ 13,
	  e = 2 ^ 14,
	  f = 2 ^ 15,
    }
    for i=0,9 do
	  tHex[i] = 2 ^ i
    end
	
    local function vertScroll(text,obj)
	  local term = obj or term
	  local termX,termY = term.getSize() -- get terminal size
	  local cursX,cursY = term.getCursorPos() --get current cursor position, so it will print to wherever the cursor is currently located
	  local scrollLength = termX-cursX+1 -- calculate visible area
	  for i = 1,#text+scrollLength do --loop the length of the text and the length of the visible area
		    term.setCursorPos(cursX-#text-scrollLength+i,cursY) --set the cursor offscreen by the length of the string we're scrolling, then subtract how many times we've scroll forward (i)
		    local tLines = {
			  [1] = {
			    string = string.rep(" ",scrollLength),
			    color = tHex[1]
			  }
		    } --table containing the strings seperated by color tags, and what color they should be
		    for color, line in text:gmatch("&([0-9abcdef])([^&]+)") do -- loop once for every color tag followed by a number (%d) then followed by anything that's not a colortag ([&^]+)
			  print(color)
			  print(line)
			  if string.match(color,"%d") then
			    color = tonumber(color)
			  end
			  tLines[#tLines+1] = {
				    string = line, --store the line to the table
				    color = tHex[color] --store the color to the table
			  }
		    end
		    for i=1,#tLines do --loop once for every entry of the table
			  term.setTextColor(tLines[i].color) --set the color
			  term.write(tLines[i].string) --write the text
		    end
		    sleep(0.2) --pause between each scroll
	  end
	  term.setCursorPos(cursX,cursY) --return the cursor to it's original position
    end
    local mon = peripheral.wrap("back")
    mon.setTextScale(1.0)
    mon.clear()
    mon.setCursorPos(1, 1)
    for i = 1, #rules do
	  vertScroll(rules[i],mon)
    end

ShadowCreeper559 #11
Posted 09 March 2014 - 04:09 PM
ok so this works now but it prints the text over the last
CometWolf #12
Posted 09 March 2014 - 04:55 PM
So, you want this basically?
If you really want multiple scrolling lines at the same time, it shoudl be pretty easily doable with the parallel api. I can show you if you need it.
theoriginalbit #13
Posted 09 March 2014 - 11:24 PM
Also, i had to remove the newline characters, since they just show up as question marks when you use write anyways.
Well thats why when I wrote this code (link) for CraftAU I made it redirect — using term.redirect — the terminal to the monitor so I could use write not mon.write doing so meant that special characters like newlines and tabs are actually obeyed as opposed to printing ?
You did vertical scrolling quite a difficult way, you basically reinvented the entire script as well as the wheel, all you needed to add was a term.scroll call with some minor extra logic.
Edited on 09 March 2014 - 10:30 PM
CometWolf #14
Posted 10 March 2014 - 05:19 AM
Redirect is still possible to use with the function i posted. Just redirect then use function without passing an object, or pass term. term.scroll is horizon…. Oh wait, FUCK! I mixed up vertical and horizontal didn't i? The one i made goes sideways…
theoriginalbit #15
Posted 10 March 2014 - 05:22 AM
Redirect is still possible to use with the function i posted. Just redirect then use function without passing an object, or pass term.
except that when you pass a monitor object it invokes mon.write which doesn't allow for special characters…

term.scroll is horizon…. Oh wait, [redacted]! I mixed up vertical and horizontal didn't i? The one i made goes sideways…
yeah you did.