Jump to content




Make Computercraft Save And Store The Screen?


  • You cannot reply to this topic
5 replies to this topic

#1 Dejected

  • Members
  • 48 posts
  • LocationPhiladelphia, Pennsylvania

Posted 22 July 2013 - 01:42 PM

I Was Wondering If There Is A Way To Make Computercraft Save The State Of The Screen And Store It To Show Again Later.
Im Currently Working On A Wireless Controlled Turtle And It Show Where There's Block And Where There's Not And To Be Able To Go Up And Down The Z Level I Would Need To Save The Screen So That When They Go Back To That Level Then You Can Still See Where Everything Is And Not Have To Re Explore The Level You Already Explored.

#2 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 22 July 2013 - 01:47 PM

You'll have to do something called "buffering" the screen.

Basically, you'll have to redirect the terminal API to write to a "buffer". This buffer is most commonly a table of strings which act as the characters on the screen. The buffer also has tables for the text colors and background colors for each of the pixels on the screen.

Here is a buffer file which I've been using to handle windowing:

Pixel
Spoiler

Buffer
Spoiler

If you're a stickler for memory management (which you should be :P), you could use strings for all of the lines, text color, and background colors. However, you'll need to serialize the colors and write similar functions for the terminal API to write to your buffer and still behave properly.

#3 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 26 July 2013 - 05:02 PM

Or you can store values in a table.

#4 Dejected

  • Members
  • 48 posts
  • LocationPhiladelphia, Pennsylvania

Posted 10 September 2013 - 04:25 PM

View PostMKlegoman357, on 26 July 2013 - 05:02 PM, said:

Or you can store values in a table.
Hey I know you... lol

#5 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 10 September 2013 - 04:35 PM

the best option for something like that is to save the table containing the data using:
local function savePrefs(name,data) -- saves data to a file
local file=fs.open(name,"w")
file.write(textutils.serialize(data))
file.close()
end
local function readPrefs(name) -- reads data from a file
local file=fs.open(name,"r")
if not file then return false end
local dat
dat=textutils.unserialize(file.readAll())
file.close()
return dat
end
-- reading
local data=readPrefs("filename") or {defaultstuff}
-- writing
savePrefs("filename",data)


#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 September 2013 - 08:27 PM

This shouldn't be dependent on saving the screen, you should save the underlying data that you're using to write to the screen. Much easier to simply re-draw the screen from the data as needed than to buffer the screen unnecessarily.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users