Posted 24 August 2012 - 09:46 AM
Hello,
I have been playing Tekkit (singleplayer) for a while now and about 1 and a half weeks ago I decided to try out the computercraft bit of it. Not having any knowledge of Lua or any other programming language I have been fiddling around with other people their scripts and some of my own. There are 2 things I want computercraft to do and that is control my machines with bundled cables and having a status screen show if everey machine is on or off. The first I have tried many scripts that were already available on this forum and I ended up liking this one: http://96.31.75.244/...-programs/]link.
I have modified it to control my machines but the problem is that when I quit the game and load it again all machines are off no matter what state they were in when I quit the game, is there any way to fix this?
code:
while true do
term.clear()
term.setCursorPos( 1, 1)
print("Master Control Unit Page 1")
print("What Machine would you like to access?")
print("_______________________________")
print("")
print("[1] Nuclear Reactor")
print("[2] Quarry 1")
print("[3] Quarry 2")
print("[4] Refinery")
print("[5] Pump fuel to quarry")
print("[6] Geothermal generators")
print("[7] ")
print("[8] ")
print("[9] ")
print("[0] ")
print("Hit [SPACE] for next page")
print("Hit [R] to reset machines on this page")
print("")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then one() end
if event == "char" and param1 == "2" then two() end
if event == "char" and param1 == "3" then three() end
if event == "char" and param1 == "4" then four() end
if event == "char" and param1 == "5" then five() end
if event == "char" and param1 == "6" then six() end
if event == "char" and param1 == "7" then seven() end
if event == "char" and param1 == "8" then eight() end
if event == "char" and param1 == "9" then nine() end
if event == "char" and param1 == "0" then zero() end
if event == "char" and param1 == " " then main2() end
if event == "char" and param1 == "r" then reset("back") end
end
end
function main2()
while true do
term.clear()
term.setCursorPos( 1, 1)
print("Master Control Unit Page 2")
print("What Machine would you like to access?")
print("_______________________________")
print("")
print("[1] ")
print("[2] ")
print("[3] ")
print("[4] ")
print("[5] ")
print("[6] ")
print("[7] ")
print("[8] ")
print("[9] ")
print("[0] ")
print("Hit [SPACE] for next page")
print("Hit for previous page")
print("Hit [R] to reset machines on this page")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then one1() end
if event == "char" and param1 == "2" then two1() end
if event == "char" and param1 == "3" then three1() end
if event == "char" and param1 == "4" then four1() end
if event == "char" and param1 == "5" then five1() end
if event == "char" and param1 == "6" then six1() end
if event == "char" and param1 == "7" then seven1() end
if event == "char" and param1 == "8" then eight1() end
if event == "char" and param1 == "9" then nine1() end
if event == "char" and param1 == "0" then zero1() end
if event == "char" and param1 == "b" then main1() end
if event == "char" and param1 == " " then main3() end
if event == "char" and param1 == "r" then reset("left") end
end
end
function main3()
while true do
term.clear()
term.setCursorPos( 1, 1)
print("Master Control Unit Page 3")
print("What Machine would you like to access?")
print("_______________________________")
print("")
print("[1] ")
print("[2] ")
print("[3] ")
print("[4] ")
print("[5] ")
print("[6] ")
print("[7] ")
print("[8] ")
print("[9] ")
print("[0] ")
print("Hit for previous page")
print("Hit [R] to reset machines on this page")
print("")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then one2() end
if event == "char" and param1 == "2" then two2() end
if event == "char" and param1 == "3" then three2() end
if event == "char" and param1 == "4" then four2() end
if event == "char" and param1 == "5" then five2() end
if event == "char" and param1 == "6" then six2() end
if event == "char" and param1 == "7" then seven2() end
if event == "char" and param1 == "8" then eight2() end
if event == "char" and param1 == "9" then nine2() end
if event == "char" and param1 == "0" then zero2() end
if event == "char" and param1 == "b" then main2() end
if event == "char" and param1 == "r" then reset("right") end
end
end
function on(x, y, z)
if rs.testBundledInput(z, x)==true then
print(y.." already on")
sleep(1)
main1()
else
rs.setBundledOutput(z, rs.getBundledOutput(z) + x)
print(y.." on")
sleep(1)
main1()
end
end
function off(x, y, z)
if rs.testBundledInput(z, x)==false then
print(y.." already off")
sleep(1)
main1()
else
rs.setBundledOutput(z, rs.getBundledOutput(z) - x)
print(y.." off")
sleep(1)
main1()
end
end
function check(x, y, z)
if rs.testBundledInput(z, x)==false then
print(y.." off")
sleep(2)
term.clear()
term.setCursorPos( 1, 1)
main1()
end
if rs.testBundledInput(z, x)==true then
print(y.." on")
sleep(2)
term.clear()
term.setCursorPos( 1, 1)
main1()
end
end
function menu(x, y, z)
while true do
term.clear()
term.setCursorPos( 1, 1)
print(y.." Control Selected")
print("")
print("[1] Turn on " ..y)
print("[2] Turn off " ..y)
print("[3] Check Status")
print("[4] Return to Main Menu")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then on(x, y, z) end
if event == "char" and param1 == "2" then off(x, y, z) end
if event == "char" and param1 == "3" then check(x, y, z) end
if event == "char" and param1 == "4" then main1() end
end
end
function reset(z)
rs.setBundledOutput(z ,0)
print("Machines reset")
term.setCursorPos( 1, 18)
term.clearLine()
sleep(1)
end
function one()
menu(256, "Nuclear reactor", "bottom")
end
function two()
menu(1, "Quarry 1", "bottom")
end
function three()
menu(16384, "Quarry 2", "bottom")
end
function four()
menu(2048, "Refinery", "bottom")
end
function five()
menu(32, "Pump fuel to quarries", "bottom")
end
function six()
menu(2, "Geothermal generators", "bottom")
end
function seven()
menu(colors.black, "[Machine]", "back")
end
function eight()
menu(colors.green, "[Machine]", "back")
end
function nine()
menu(colors.black, "[Machine]", "back")
end
function zero()
menu(colors.black, "[Machine]", "back")
end
function one1()
menu(colors.black, "[Machine]", "left")
end
function two1()
menu(colors.black, "[Machine]", "left")
end
function three1()
menu(colors.black, "[Machine]", "left")
end
function four1()
menu(colors.black, "[Machine]", "left")
end
function five1()
menu(colors.black, "[Machine]", "left")
end
function six1()
menu(colors.black, "[Machine]", "left")
end
function seven1()
menu(colors.black, "[Machine]", "left")
end
function eight1()
menu(colors.green, "[Machine]", "left")
end
function nine1()
menu(colors.black, "[Machine]", "left")
end
function zero1()
menu(colors.black, "[Machine]", "left")
end
function one2()
menu(colors.black, "[Machine]", "right")
end
function two2()
menu(colors.black, "[Machine]", "right")
end
function three2()
menu(colors.black, "[Machine]", "right")
end
function four2()
menu(colors.black, "[Machine]", "right")
end
function five2()
menu(colors.black, "[Machine]", "right")
end
function six2()
menu(colors.black, "[Machine]", "right")
end
function seven2()
menu(colors.black, "[Machine]", "right")
end
function eight2()
menu(colors.green, "[Machine]", "right")
end
function nine2()
menu(colors.black, "[Machine]", "right")
end
function zero2()
menu(colors.black, "[Machine]", "right")
end
main1()
The status screen is giving me more of a headache, I was somehow not able to find anything on here that suited my needs (maybe I am using the wrong words to search for it) so I decided to try it out myself but it only does what I want in certain states, if I turn on the quarry the script keeps spamming the 2 lines until it quits with the too long without yielding message. Could somebody fix the script below so I can edit it myself to feature all my machines? I just want it to show my machines with their online or offline status behind it, updating every 1 to 2 seconds.
code:
term.clear()
term.setCursorPos( 1, 1)
if rs.testBundledInput("back", 256) == true
then print("Nuclear reactor on")
else print("Nuclear reactor off")
if rs.testBundledInput("back", 2048) == true
then print("Quarry 1 on")
else print("Quarry 1 off")
break
end
end
end
I actually hate to ask for help because I rather do things like this myself but I have tried so many things to fix this that I have lost sight on what could be wrong.
I have been playing Tekkit (singleplayer) for a while now and about 1 and a half weeks ago I decided to try out the computercraft bit of it. Not having any knowledge of Lua or any other programming language I have been fiddling around with other people their scripts and some of my own. There are 2 things I want computercraft to do and that is control my machines with bundled cables and having a status screen show if everey machine is on or off. The first I have tried many scripts that were already available on this forum and I ended up liking this one: http://96.31.75.244/...-programs/]link.
I have modified it to control my machines but the problem is that when I quit the game and load it again all machines are off no matter what state they were in when I quit the game, is there any way to fix this?
code:
Spoiler
function main1()while true do
term.clear()
term.setCursorPos( 1, 1)
print("Master Control Unit Page 1")
print("What Machine would you like to access?")
print("_______________________________")
print("")
print("[1] Nuclear Reactor")
print("[2] Quarry 1")
print("[3] Quarry 2")
print("[4] Refinery")
print("[5] Pump fuel to quarry")
print("[6] Geothermal generators")
print("[7] ")
print("[8] ")
print("[9] ")
print("[0] ")
print("Hit [SPACE] for next page")
print("Hit [R] to reset machines on this page")
print("")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then one() end
if event == "char" and param1 == "2" then two() end
if event == "char" and param1 == "3" then three() end
if event == "char" and param1 == "4" then four() end
if event == "char" and param1 == "5" then five() end
if event == "char" and param1 == "6" then six() end
if event == "char" and param1 == "7" then seven() end
if event == "char" and param1 == "8" then eight() end
if event == "char" and param1 == "9" then nine() end
if event == "char" and param1 == "0" then zero() end
if event == "char" and param1 == " " then main2() end
if event == "char" and param1 == "r" then reset("back") end
end
end
function main2()
while true do
term.clear()
term.setCursorPos( 1, 1)
print("Master Control Unit Page 2")
print("What Machine would you like to access?")
print("_______________________________")
print("")
print("[1] ")
print("[2] ")
print("[3] ")
print("[4] ")
print("[5] ")
print("[6] ")
print("[7] ")
print("[8] ")
print("[9] ")
print("[0] ")
print("Hit [SPACE] for next page")
print("Hit for previous page")
print("Hit [R] to reset machines on this page")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then one1() end
if event == "char" and param1 == "2" then two1() end
if event == "char" and param1 == "3" then three1() end
if event == "char" and param1 == "4" then four1() end
if event == "char" and param1 == "5" then five1() end
if event == "char" and param1 == "6" then six1() end
if event == "char" and param1 == "7" then seven1() end
if event == "char" and param1 == "8" then eight1() end
if event == "char" and param1 == "9" then nine1() end
if event == "char" and param1 == "0" then zero1() end
if event == "char" and param1 == "b" then main1() end
if event == "char" and param1 == " " then main3() end
if event == "char" and param1 == "r" then reset("left") end
end
end
function main3()
while true do
term.clear()
term.setCursorPos( 1, 1)
print("Master Control Unit Page 3")
print("What Machine would you like to access?")
print("_______________________________")
print("")
print("[1] ")
print("[2] ")
print("[3] ")
print("[4] ")
print("[5] ")
print("[6] ")
print("[7] ")
print("[8] ")
print("[9] ")
print("[0] ")
print("Hit for previous page")
print("Hit [R] to reset machines on this page")
print("")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then one2() end
if event == "char" and param1 == "2" then two2() end
if event == "char" and param1 == "3" then three2() end
if event == "char" and param1 == "4" then four2() end
if event == "char" and param1 == "5" then five2() end
if event == "char" and param1 == "6" then six2() end
if event == "char" and param1 == "7" then seven2() end
if event == "char" and param1 == "8" then eight2() end
if event == "char" and param1 == "9" then nine2() end
if event == "char" and param1 == "0" then zero2() end
if event == "char" and param1 == "b" then main2() end
if event == "char" and param1 == "r" then reset("right") end
end
end
function on(x, y, z)
if rs.testBundledInput(z, x)==true then
print(y.." already on")
sleep(1)
main1()
else
rs.setBundledOutput(z, rs.getBundledOutput(z) + x)
print(y.." on")
sleep(1)
main1()
end
end
function off(x, y, z)
if rs.testBundledInput(z, x)==false then
print(y.." already off")
sleep(1)
main1()
else
rs.setBundledOutput(z, rs.getBundledOutput(z) - x)
print(y.." off")
sleep(1)
main1()
end
end
function check(x, y, z)
if rs.testBundledInput(z, x)==false then
print(y.." off")
sleep(2)
term.clear()
term.setCursorPos( 1, 1)
main1()
end
if rs.testBundledInput(z, x)==true then
print(y.." on")
sleep(2)
term.clear()
term.setCursorPos( 1, 1)
main1()
end
end
function menu(x, y, z)
while true do
term.clear()
term.setCursorPos( 1, 1)
print(y.." Control Selected")
print("")
print("[1] Turn on " ..y)
print("[2] Turn off " ..y)
print("[3] Check Status")
print("[4] Return to Main Menu")
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then on(x, y, z) end
if event == "char" and param1 == "2" then off(x, y, z) end
if event == "char" and param1 == "3" then check(x, y, z) end
if event == "char" and param1 == "4" then main1() end
end
end
function reset(z)
rs.setBundledOutput(z ,0)
print("Machines reset")
term.setCursorPos( 1, 18)
term.clearLine()
sleep(1)
end
function one()
menu(256, "Nuclear reactor", "bottom")
end
function two()
menu(1, "Quarry 1", "bottom")
end
function three()
menu(16384, "Quarry 2", "bottom")
end
function four()
menu(2048, "Refinery", "bottom")
end
function five()
menu(32, "Pump fuel to quarries", "bottom")
end
function six()
menu(2, "Geothermal generators", "bottom")
end
function seven()
menu(colors.black, "[Machine]", "back")
end
function eight()
menu(colors.green, "[Machine]", "back")
end
function nine()
menu(colors.black, "[Machine]", "back")
end
function zero()
menu(colors.black, "[Machine]", "back")
end
function one1()
menu(colors.black, "[Machine]", "left")
end
function two1()
menu(colors.black, "[Machine]", "left")
end
function three1()
menu(colors.black, "[Machine]", "left")
end
function four1()
menu(colors.black, "[Machine]", "left")
end
function five1()
menu(colors.black, "[Machine]", "left")
end
function six1()
menu(colors.black, "[Machine]", "left")
end
function seven1()
menu(colors.black, "[Machine]", "left")
end
function eight1()
menu(colors.green, "[Machine]", "left")
end
function nine1()
menu(colors.black, "[Machine]", "left")
end
function zero1()
menu(colors.black, "[Machine]", "left")
end
function one2()
menu(colors.black, "[Machine]", "right")
end
function two2()
menu(colors.black, "[Machine]", "right")
end
function three2()
menu(colors.black, "[Machine]", "right")
end
function four2()
menu(colors.black, "[Machine]", "right")
end
function five2()
menu(colors.black, "[Machine]", "right")
end
function six2()
menu(colors.black, "[Machine]", "right")
end
function seven2()
menu(colors.black, "[Machine]", "right")
end
function eight2()
menu(colors.green, "[Machine]", "right")
end
function nine2()
menu(colors.black, "[Machine]", "right")
end
function zero2()
menu(colors.black, "[Machine]", "right")
end
main1()
The status screen is giving me more of a headache, I was somehow not able to find anything on here that suited my needs (maybe I am using the wrong words to search for it) so I decided to try it out myself but it only does what I want in certain states, if I turn on the quarry the script keeps spamming the 2 lines until it quits with the too long without yielding message. Could somebody fix the script below so I can edit it myself to feature all my machines? I just want it to show my machines with their online or offline status behind it, updating every 1 to 2 seconds.
code:
Spoiler
while true doterm.clear()
term.setCursorPos( 1, 1)
if rs.testBundledInput("back", 256) == true
then print("Nuclear reactor on")
else print("Nuclear reactor off")
if rs.testBundledInput("back", 2048) == true
then print("Quarry 1 on")
else print("Quarry 1 off")
break
end
end
end
I actually hate to ask for help because I rather do things like this myself but I have tried so many things to fix this that I have lost sight on what could be wrong.