Help with infinite loop and auto start
#1
Posted 25 October 2012 - 05:13 PM
what i have gotten so far is how to display the text to the top monitor with this code
local tText = {
"multiple",
"lines",
" of info"
}
local sSide = "top"
local nTextSize = 1.5 -- change the text size here (from 1 to 5)
local function printCenter(mon, t)
local w, h = mon.getSize()
local y = math.floor((h / 2) - (#t / 2)) - 1
for i, line in ipairs(t) do
local x = math.floor((w / 2) - (#line / 2))
mon.setCursorPos(x, y + i)
mon.write(line)
end
end
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, tText)
what i would also like to do is have the script display 3 different screens of info with a timer between each page being displayed, i did some searching and i think im supposed to use os.sleep for the timer, just not sure how or where to put the code for the second page, i assume i need to clear screen b4 each display with monitor.clear
as for infinite loop i have seen some post to use something like: local function infiniteloop while true do do stuff, and what would i need to do to make this start when my server goes through its scheduled restarts
im just not sure how to put all this information together to make a workable script as i have no coding experience
thanks for any help
#2
Posted 25 October 2012 - 05:21 PM
while true do screen1() os.sleep(5) //5 seconds screen2() os.sleep(5) screen3() os.sleep(5) end
However, I do not know if you can have a computer turn on after the server restart without clicking on it. I am sure someone else here can answer that part.
#3
Posted 25 October 2012 - 05:37 PM
#4
Posted 25 October 2012 - 05:49 PM
#5
Posted 25 October 2012 - 06:16 PM
function screen1()
code
end
my next question is can i make the functions after the while true do loop at the beginning
so it the code would look like :
while true do
screen1()
end
function screen1()
code
end
#6
Posted 25 October 2012 - 06:21 PM
#7
Posted 25 October 2012 - 06:31 PM
#8
Posted 25 October 2012 - 06:51 PM
Ditto8353, on 25 October 2012 - 06:31 PM, said:
You can also just forward declare it.
local f, g -- 'forward' declarations function g () return f() end function f () return 42 end print( g() )
Just sharing this with the people that don't know yet.
#9
Posted 25 October 2012 - 06:54 PM
local test
test()
local function test()
print("It works")
end
input:3: attempt to call local 'test' (a nil value)
#10
Posted 25 October 2012 - 06:56 PM
#11
Posted 25 October 2012 - 08:30 PM
Ditto8353, on 25 October 2012 - 06:54 PM, said:
local test
test()
local function test()
print("It works")
end
input:3: attempt to call local 'test' (a nil value)
Do you know the difference between declaring and defining? Anyways, it seems that you need to have them defined before you're at the point of calling them anyway.
#12
Posted 25 October 2012 - 09:40 PM
shell.run("monitor", "back", "test")
just change the back to the direction you need and the test to what your program is called. simple
#13
Posted 25 October 2012 - 10:57 PM
how would i set this code
local tText = {
"multiple",
"lines",
" of info"
}
local sSide = "top"
local nTextSize = 1.5 -- change the text size here (from 1 to 5)
local function printCenter(mon, t)
local w, h = mon.getSize()
local y = math.floor((h / 2) - (#t / 2)) - 1
for i, line in ipairs(t) do
local x = math.floor((w / 2) - (#line / 2))
mon.setCursorPos(x, y + i)
mon.write(line)
end
end
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, tText)
in a function to be called screen1 using the method posted early with while true do
#14
Posted 25 October 2012 - 11:56 PM
while true do
function screen1()
local aText = {
"Welcome to Miners' Haven Tekkit Server",
"",
" server ",
"info",
" goes ",
"here"
}
local sSide = "top"
local nTextSize = 1.5 -- change the text size here (from 1 to 5)
local function printCenter(mon, a)
local w, h = mon.getSize()
local y = math.floor((h / 2) - (#a / 2)) - 1
for i, line in ipairs(a) do
local x = math.floor((w / 2) - (#line / 2))
mon.setCursorPos(x, y + i)
mon.write(line)
end
end
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, aText)
os.sleep(10)
monitor.clear()
end
screen1()
function screen2()
local bText = {
"Welcome to Server",
"",
"some",
"more",
"info",
"here"
}
local sSide = "top"
local nTextSize = 1.5 -- change the text size here (from 1 to 5)
local function printCenter(mon, ^_^/>/>
local w, h = mon.getSize()
local y = math.floor((h / 2) - (#b / 2)) - 1
for i, line in ipairs(:P/>/> do
local x = math.floor((w / 2) - (#line / 2))
mon.setCursorPos(x, y + i)
mon.write(line)
end
end
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, bText)
os.sleep(10)
monitor.clear()
end
screen2()
end
after my 10 second delay i get attempt to index ? (a nil value) which also occurs if try monitor.clear(top) im not sure what im doing wrong but at that error the script halts and will not continue, it will however display the first set of text to the monitor
#15
Posted 26 October 2012 - 12:05 AM
monitor.clear()should be
mon.clear()
#16
Posted 26 October 2012 - 12:18 AM
http://www.computerc...eripheral_(API)
it has monitor.clear()
but thanks so much to everyone who helped, now i gotta try that startup script charlie posted
again thanks everyone
#17
Posted 26 October 2012 - 03:02 PM
wannab, on 26 October 2012 - 12:18 AM, said:
http://www.computerc...eripheral_(API)
it has monitor.clear()
but thanks so much to everyone who helped, now i gotta try that startup script charlie posted
again thanks everyone
Yes, and it also says that you're supposed to replace 'monitor' with whatever variable you wrapped that side into.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











