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

Bulletin Board scale issue

Started by Aerik, 01 July 2012 - 09:48 PM
Aerik #1
Posted 01 July 2012 - 11:48 PM
Hey dear fellow programmers,
I made this program for a bulletin board at my server, however, there is a slight issue with the code.
When set to textscale 2, it works fine, but the text is too big to fit on the screen. Using scale 1, however, will not print the most important parts of the board. It does not print the "layout", "header" and "info" parts, while it does actually print the line from "print1" when receiving the rednet message. I have no idea what causes this problem, so any help would be greatly appreciated!

Also, any tips on how to further improve this code are welcome as well!

http://pastebin.com/D9kMGQr4


rednet.open("right")
monitor = peripheral.wrap("top")
monitor.setTextScale(1)
tw,th = term.getSize()
mw,mh = monitor.getSize()
serverID = 151
incursions = 0

local function mPrint(str, ypos)
 monitor.setCursorPos(1, ypos)
 monitor.write(str)
end

local function tPrintCentered(str, ypos)
 term.setCursorPos(tw/2 - #str/2, ypos)
 term.write(str)
end
local function mPrintCentered(str, ypos)
 monitor.setCursorPos(mw/2 - #str/2, ypos)
 monitor.write(str)
end

local function tPrintD(str1, str2, ypos)
 term.setCursorPos(1, ypos)
 term.write(str1)
 term.setCursorPos(tw/2, ypos)
 term.write(str2)
end
local function mPrintD(str1, str2, ypos)
 monitor.setCursorPos(1, ypos)
 monitor.write(str1)
 monitor.setCursorPos(mw/2, ypos)
 monitor.write(str2)
end

local function tPrintDC(str1, str2, ypos)
 term.setCursorPos((tw/4) - (#str1/2), ypos)
 term.write(str1)
 term.setCursorPos(tw - (tw/4) -(#str2/2), ypos)
 term.write(str2)
end
local function mPrintDC(str1, str2, ypos)
 monitor.setCursorPos((mw/4) - (#str1/2), ypos)
 monitor.write(str1)
 monitor.setCursorPos(mw - (mw/4) - (#str2/2), ypos)
 monitor.write(str2)
end


local function layout(line)
 for n=2, mh-1, 1 do
  monitor.setCursorPos(1, n)
  monitor.write("|")
  monitor.setCursorPos(mw, n)
  monitor.write("|")
 end
 monitor.setCursorPos(1, line)
 monitor.write("+")
 for n=2, mw-1, 1 do
  monitor.setCursorPos(n, line)
  monitor.write("-")
 end
 monitor.setCursorPos(mw, line)
 monitor.write("+")
end

local function redraw(line)
 monitor.setCursorPos(mw, line)
 monitor.write("|")
end


local function header()
 mPrint("  _____ _   _						 _	____				 _			 ",2)
 mPrint(" | ____| |_| |__   ___ _ __ ___  __ _| |  / ___| __ _ _ __ ___ (_)_ __   __ _ ",3)
 mPrint(" |  _| | __| '_  / _  '__/ _ / _` | | | |  _ / _` | '_ ` _ | | '_  / _` |",4)
 mPrint(" | |___| |_| | | |  __/ | |  __/ (_| | | | |_| | (_| | | | | | | | | | | (_| |",5)
 mPrint(" |_____|__|_| |_|___|_|  ___|__,_|_|  ____|__,_|_| |_| |_|_|_| |_|__, |",6)
 mPrint("																		|___/ ",7)
 for line=2,7,1 do
  redraw(line)
 end
end


local function info()
 mPrintC("Welcome to the Ethereal Gaming tekkit server!", 9)
 mPrintC("Please adhere to the following rules:", 11)
 mPrintDC("1. No spam", "3. No hacking", 12)
 mPrintDC("2. No griefing", "4. No duping", 13)
 mPrintC("5. No hassling admins.", 14)
 for n=9,14,1 do
  redraw(n)
 end
end


local function print1()
 mPrintC("This MOTD is currently empty...", 16)
 redraw(16)
end
local function print2()
 mPrintC("This MOTD is currently empty...", 16)
 redraw(16)
end
local function print3()
 mPrintC("This MOTD is currently empty...", 16)
 redraw(16)
end
local function print4()
 mPrintC("This MOTD is currently empty...", 16)
 redraw(16)
end
local function print5()
 mPrintC("This MOTD is currently empty...", 16)
 redraw(16)
end

local function incursion()
 mPrintC("INCURSION DETECTED", mh-1)
 redraw(mh-1)
 incursions = incursions+1
end

local function reboot()
 os.reboot()
end

local function terminate()
 os.shutdown()
end

local function exit()
 break end


local function listen()
 id,message = rednet.receive()
 if id == serverID then
  if message == "print1" then
   print1()
  elseif message == "print2" then
   print2()
  elseif message == "print3" then
   print3()
  elseif message == "print4" then
   print4()
  elseif message == "print5" then
   print5()
  elseif message == "reboot" then
   reboot()
  elseif message == "terminate" then
   terminate()
  elseif message == "exit" then
   exit()
  end
 elseif id ~= serverID then
  incursion()
 end
end

function main()
 layout(1)
 layout(8)
 layout(15)
 header()
 info()
 while true do
  listen()
 end
end

main()
Aerik #2
Posted 05 July 2012 - 12:06 AM
-bump-
MysticT #3
Posted 05 July 2012 - 12:18 AM
Well, I don't think that would even run, because this function:

local function exit()
  break end
would throw an error (something like "nothing to break").
Aerik #4
Posted 06 July 2012 - 01:03 AM
Actually, it doesn't, since I run the "exit" program in the "listen" loop, and only execute it when it receives the string "exit" through rednet.
The problem is that it doesn't print when on textscale 1, it does print on scale 2, but that doesn't fit…
MysticT #5
Posted 06 July 2012 - 01:11 AM
Actually, it doesn't, since I run the "exit" program in the "listen" loop, and only execute it when it receives the string "exit" through rednet.
The problem is that it doesn't print when on textscale 1, it does print on scale 2, but that doesn't fit…
No you don't, you call the exit function. If you try to run the program, it throws a "no loop to break" error.
Aerik #6
Posted 06 July 2012 - 04:53 AM
Okay, in that case, I probably fixed this error in my latest version (playing on a server, so I don't have direct access to those files).
Anyway, this exit function is NOT the issue, I already finished the debugging shit, no more errorthrowing.
Again, my only issue is it not printing at scale 1. Only problem.
MysticT #7
Posted 06 July 2012 - 05:46 PM
Well, without the actual working code, we can't help. There's no reason for the text to don't show with different text scale.