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

term.restore returning error

Started by destruktoid, 19 August 2012 - 03:32 AM
destruktoid #1
Posted 19 August 2012 - 05:32 AM
I have my computer display text on an adjacent monitor at startup, but instead of displaying the text on the monitor, it says bios:206: [string "startup"]:11: '=' expected . Have i done something wrong? Its never happened to me before. Btw, im new to Lua :D/>/>
Cranium #2
Posted 19 August 2012 - 05:33 AM
Post your code, and we'll take a look at it.
destruktoid #3
Posted 19 August 2012 - 05:48 AM

local leftmon = peripheral.wrap("left")
term.redirect(leftmon)
print("SYSTEM STARTUP")
sleep(2)
print("LOADING")
sleep(1)
print("SYSTEMS ONLINE")
rs.setBundledOutput("top",rs.getBundledOutput("top") + colors.yellow)
sleep(5)
term.clear
term.restore()
Cranium #4
Posted 19 August 2012 - 05:53 AM
your term.clear should be term.clear()
destruktoid #5
Posted 19 August 2012 - 05:56 AM
that works, now im getting
startup:3: attempt to call nil
Cranium #6
Posted 19 August 2012 - 06:02 AM
Ah. I believe you need to use write instead of print. I don't think peripheral.wrap likes print commands.
destruktoid #7
Posted 19 August 2012 - 06:32 AM
that workd, but now it prints all in one line. what do i add to make it go to a new line? or is it term.setcursorpos?
Cranium #8
Posted 19 August 2012 - 06:36 AM
What you can do is either use term.setCursorPos, or on the end of each write command, you can use "n" before you close the quotations. That gives it the command to go to the next line.
destruktoid #9
Posted 19 August 2012 - 06:43 AM
is there a way of centering the text without using printCenter?
Cranium #10
Posted 19 August 2012 - 07:26 AM
Er…the only way I know, is really complicated… But I'll show you, cause it's really useful(in small amounts):

local w,h = term.getSize() --returns width, height of terminal. Can be used with mon.getSize()
local string = "your words here"
local b = string.len(string)/2 --divides the length of the string here in two.
--now for some math-jiggery to get it to print center:
local x = (w/2)-b --taking the term or mon width, dividing by two, and subtracting the first half of the string.
local y = h/2 --dividing the height by two.
term.setCursorpos(x,y) -- now will start at just before center, so that your previous string is centered.
print(string)
Like I said, it's a little complicated, and you could actually go one step further like this:

local tab = {
"first line here",
"second line here",
"and so on..."
}
--do the same math as above, but this time, while using string.len, use this:
for i,#tab do --this will get the length of each line, and print right after
local b = string.len(tab[i]) --the variable "i" will increase the number of lines you have in tab.
print(tab[i])
end
destruktoid #11
Posted 19 August 2012 - 07:31 AM
at my current level i wont try use that, but ill come back to it later. thanks for the help!
Cloudy #12
Posted 20 August 2012 - 02:20 PM
print should work fine - it doesnt care what is being redirected.
Cranium #13
Posted 20 August 2012 - 03:04 PM
Should it be print then, or leftmon.print in this instance?
Lyqyd #14
Posted 20 August 2012 - 03:10 PM
Should it be print then, or leftmon.print in this instance?

Just print(). The monitor does not expose a print method.
Cranium #15
Posted 20 August 2012 - 03:13 PM
So I'm wondering why line 3 on his code threw an error then…