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

Scrolling wrappable text in a limited frame

Started by limdingwen, 30 July 2012 - 01:36 PM
limdingwen #1
Posted 30 July 2012 - 03:36 PM
I'm making an IRC chat program, but I have no clue how to make a frame scroll by itself when it has reached the ending line of the frame. The default scrolling for print() won't work because that works for full screen only. Any ideas?
twormtwo #2
Posted 01 August 2012 - 07:30 PM
You may want to put each message into its own section in a table. Example:
Put this on the top:

local messages = { }
local num = 0
shownMessages = 0
maxMessagesOnScreen = 10 --This can be changed to however many you want
And then this in where you get the messages

messages[num] = receivedMessage
num = num+1
Then when you go to display it, check how many lines it can show on the screen and then write that many lines from the ending (#messages will return a number, how many messages are in the table). Example:

if #messages > maxMessagesOnScreen then
  shownMessages = (#messages - maxMessagesOnScreen)
elseif #messages < maxMessagesOnScreen then
  shownMessages = #message
end
for b = 2, shownMessages do
  print(messages[b])
end
Hope this helps you!