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

Mougli123's Programs

Started by mougli123, 12 February 2012 - 08:05 PM
mougli123 #1
Posted 12 February 2012 - 09:05 PM
Here are the programs I've coded so far.

Master Control Terminal
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] ")
  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 [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 [B] 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 [B] 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(colors.black, "[Machine]", "back")
end

function two()
menu(colors.black, "[Machine]", "back")
end

function three()
menu(colors.black, "[Machine]", "back")
end

function four()
menu(colors.black, "[Machine]", "back")
end

function five()
menu(colors.black, "[Machine]", "back")
end

function six()
menu(colors.black, "[Machine]", "back")
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 variable "x" is colors. ; to make this work, all colors are set to black, you should change this to suit your setup.
The variable "y" is [Machine] ; Replace [Machine] with the name of the machine.
The variable "z" is the side the bundled cable is on in quotes.
This code is able to control up to 30 machines at once. Referring to any machine that can be affected by a redstone current (industrialcraft, buildcraft, redpower, etc.)

Floppy Disk Lock
Spoiler

function main()
	term.clear()
	term.setCursorPos(1, 1)
	pass = "password"
	super = "root"
	if disk.isPresent("right") == true then
		label = disk.getLabel("right")
		if disk.hasData("right") == true then
			if label == pass then
				password()
			else
				incorrect()
			end
		end
	else
		print("Please insert a Disk")
		while true do
			event, param1 = os.pullEvent()
			if event == "disk" then
			main()
			end
			if event == "char" and param1 == "a" then
			nData()
			end
		end
	end
end

function password()
	print("Disk accepted, access granted")
	sleep(1)
	disk.eject("right")
	print("Please take your disk")
	rs.setOutput("left",true)
	sleep(10)
	os.shutdown()
end

function incorrect()
	print("Disk not recognized, access denied")
	sleep(3)
	disk.eject("right")
	main()
end

function nData()
	print("Enter Admin password now")
	write("> ")
	input = io.read()
	if input == super then
		print("Now accessing admin mode")
		sleep(2)
		admin()	
	else
		print("Incorrect password")
		sleep(2)
		main()
	end
end

function admin()
	print("Please insert disk to continue")
	while true do
		event, param1 = os.pullEvent()
		if event == "disk" then
			break
		end
	end
	print("Would you like to create a password disk?")
	input = io.read()
	write("> ")
	if input == "yes" then
		print("Copying password files to disk")
		sleep(3)
		disk.setLabel("right",pass)
		print("Disk created, please take the disk")
		sleep(5)
		disk.eject("right")
		sleep(.5)
		main()
	elseif input == "no" then
		print("Now exiting Admin mode")
		sleep(2)
		main()
	end
end
main()
This is a simple-ish program to lock a door using the label on a floppy disk.
Wolvan #2
Posted 13 February 2012 - 11:58 PM
What machines do you talk of?
Dragon53535 #3
Posted 15 February 2012 - 05:25 PM
hey, i've been using your floppy disk lock program, and editting it a bit so that it has 2 different key cards to do two different things this is my completed code:
Spoilerfunction main()
term.clear()
term.setCursorPos(1, 1)
pass = "password"
door = "bleep"
if disk.isPresent("left") == true then
label = disk.getLabel("left")
if disk.hasData("left") == true then
if label == pass then
password()
elseif label == door then
gate()
else
incorrect()
end
end
else
print("Please insert a Disk")
while true do
event, param1 = os.pullEvent()
if event == "disk" then
main()
end
if event == "char" and param1 == "c" then
nData()
end
end
end
end

function password()
print("Disk accepted, access granted")
sleep(1)
disk.eject("left")
print("Please take your disk")
rs.setOutput("right",true)
sleep(10)
os.shutdown()
end

function gate()
print ("Disk accepted, access granted")
sleep(1)
disk.eject("left")
print("Please take your disk")
rs.setOutput("back",true)
sleep(10)
os.shutdown()
end
function incorrect()
print("Disk not recognized, access denied")
sleep(3)
disk.eject("left")
main()
end

function nData()
print("Credits:")
print("Of course, Computercraft by Dan200")
print("Original script: Mougli123")
print("Helper: Espen")
sleep(10)
main()


end
main()
2nd code: Master computer code/admin code (credit to espen for fixing it for meh :D/>/>)
Spoilerfunction main()
door = "bleep"
pass = "password"
print("1: door")
print("2: gate")
input = io.read()
write("> ")
if input == "1" then
disk.setLabel("left",door)
sleep(2)
os.shutdown()
elseif input == "2" then
disk.setLabel("left",pass)
sleep(2)
os.shutdown()
end
end
main()
thank you espen, i will be editing my codes now so i can make a area where i have 1 master computer hidden away, and that computer can put the code on the disk :D/>/> prob will EVENTUALLY make a video using the codes to make them work, now to polish it more up and make messages appear when the disk it written on and such :D/>/>

Will be posting more things using your codes here whenever you come out with them :D/>/>


also, just because i wanna say it, i added a CREDITS to the keydisk lock :D/>/>
Espen #4
Posted 15 February 2012 - 06:27 PM
@Dragon53535:
os.shutdown is a function, i.e. you need to put square brackets at the end to call it, like so:
os.shutdown()
Try to change that and see if the error still persists.

Edit: Also you have an 'end' before your 'elseif', which means the 'elseif' doesn't have a beginning.
Elseif can only be the continuation of an IF-Block.
Just remove the 'end' before the 'if' and it should be fine.
Edited on 15 February 2012 - 05:29 PM
Shade25 #5
Posted 20 February 2012 - 08:10 PM
There is also a comma instead of a period on line 34:
if disk,isPresent("left") == false then main1()

needs to be:
if disk.isPresent("left") == false then main1()