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

Master Computer

Started by Ridous, 29 February 2012 - 12:58 AM
Ridous #1
Posted 29 February 2012 - 01:58 AM
I'm trying to program my computer to turn off and on select machines but I can't figure it out xD

So far I can make ALL my engines run but when I try to turn something else on they turn off. I want them to stay on while my other machine is starting to rev up.

Also I'm trying to make it if I type a "Engines" twice, they would turn off.

Any hints or help to make this possible? (right now I can't write functions all that well ^_^/>/>)
Luanub #2
Posted 29 February 2012 - 02:20 AM
What does your redstone commands look like in your code?

Make sure to do something like…



c = colors.combine ( c )

function onandoff()
print ("turning red and blue on")
c = colors.combine( c, colors.red, colors.blue )
rs.setBundledOutput("back", c )
sleep (5)
print ("turning red off, leaving blue on")
c = colors.subtract( c, colors.red )
rs.setBundledOutput("back", c )
end
Ridous #3
Posted 29 February 2012 - 07:13 AM
trying to get this code to work properly in a function but it gives me the else result when it should give the then


match = rs.getBundledInput("left")

if colors.test(match, colors.white) == ture then
rs.BudledOutput("back", colors.black)
else
print "Its not 16"
end

Luanub #4
Posted 29 February 2012 - 07:26 AM
Try this… Just have a couple of the commands wrong.



local match = ("left")

if testBundledInput(match, colors.white ) == true then
rs.setBundledOutput("back", colors.black )
else
print ("its not 16")
end
Ridous #5
Posted 29 February 2012 - 06:42 PM
That code is trying to call nil xD

This is currently all my main code, I'll be putting this off until I get that blasted EngineData program to run and send its information > :unsure:/>/>/>

Spoiler

--credit for the main menu build goes to Casper7526
--I ripped most of his tutorial code apart to do most of this.
--Mind the fact that this is a personal build and will request help if needed.
--I never used LUA before =p

--Current Version: Alpha.0 (Uncompleted Build)

--This program is ment to be run inside minecraft with the CC(ComputerCraft)
--mod. Outside of that this program does nothing.
--All feedback and switches are activated using the Laser mod for minecraft.
--along with Eloraam's RedPower2 mod for minecraft
function mainmenu()
while true do
term.clear()
term.setCursorPos(1,1)
print "-------------------------------------------------"
print "|		Factory Master Computer  Alpha 1	   |"
print "|				 Foreman: Ridous			   |"
print "-------------------------------------------------"
print "| 1. Engines									|"
print "| 2. Cooling									|"
print "| 3. Re-fuel									|"
print "| 4. Quarry									 |"
print "| 5. Bedrock Breaker							|"
print "| 6. Pumps									  |"
print "| 7. Genorators								 |"
print "| 8. Anti-Creeper System						|"
print "| 9. Factory Self-Destruct					  |"
print "| 0. Clock-out								  |"
print "|											   |"
print "|											   |"
print "|											   |"
print "-------------------------------------------------"
-- currently Bedrock Breaker is just the name for my
-- cobble genorator which can output 15 stacks in 60
-- seconds.
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "0" then break end
if event == "char" and param1 == "1" then Engines() end
if event == "char" and param1 == "2" then Cooling end
if event == "char" and param1 == "3" then Refuel() end
if event == "char" and param1 == "4" then Quarry() end
if event == "char" and param1 == "5" then BedrockBreaker() end
if event == "char" and param1 == "6" then Pumps() end
if event == "char" and param1 == "7" then Gens() end
if event == "char" and param1 == "8" then LaserDefecne() end
if event == "char" and param1 == "9" then SlefDestruct() end
end
end

function Engines()
while true do
term.clear()
term.setCursorPos(1,1)
shell.run( EngineData , onoff , match , gas75 , level , water , heatc )
-- above shell run will run EngineData and will send the variables for
-- onoff, match, gas75, level, water, and heatc
print "-------------------------------------------------"
print "|		Factory Master Computer  Alpha 1	   |"
print "|				 Foreman: Ridous			   |"
print "-------------------------------------------------"
print "|				   Engines					 |"
print "|											   |"
print "|			Currently		"..onoff.."	   |"
print "|											   |"
print "|	Current Number		   "..match.."	   |"
print "|	Full Tank?			   "..gas75.."	   |"
print "|	Water Level			  "..level.."	   |"
print "|	Cooling System?		  "..water.."	   |"
print "|	Heat Level			   "..heatc.."	   |"
print "|											   |"
print "|	Turn off/on?			   [Y] [N]		 |"
print "|											   |"
print "|											   |"
print "-------------------------------------------------"
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "y" then shell.run( EngineData , switch ) , mainmenu() end
if event == "char" and param1 == "n" then mainmenu() end
-- pressing "y" will run the switch function in EngineData to make it
-- turn off if its already on or turn it on if it was off and then send
-- you back to the main menu. Pressing "n" will just send you back to
-- to the main menu.
end
end

function Cooling()
while true do
term.clear()
term.setCursorPos(1,1)
shell,run( CoolingData, onoff , match , reser , level )
-- above shell run will run CoolingData and will send the variables for
-- onoff, match, reser, and level
print "-------------------------------------------------"
print "|		Factory Master Computer  Alpha 1	   |"
print "|				 Foreman: Ridous			   |"
print "-------------------------------------------------"
print "|				   Cooling					 |"
print "|											   |"
print "|			Currently		"..onoff.."	   |"
print "|											   |"
print "|	Current Number		   "..match.."	   |"
print "|	Full Reserves?		   "..reser.."	   |"
print "|	Heat Level			   "..level.."	   |"
print "|											   |"
print "|											   |"
print "|											   |"
print "|	Turn off/on?			   [Y] [N]		 |"
print "|											   |"
print "|											   |"
print "-------------------------------------------------"
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "y" then shell.run( CoolingData , switch ) , mainmenu() end
if event == "char" and param1 == "n" then mainmenu() end
-- pressing "y" will run the switch function in CoolingData to make it
-- turn off if its already on or turn it onif it was off and then send
-- you back to the main menu. Pressing "n" will just send you back to
-- to the main menu.
Liraal #6
Posted 29 February 2012 - 06:57 PM
cause it's wrong. try this:

local match = rs.getBundledInput("left") –you can use getBundledOutput as well

if colors.testBundledInput(match, colors.white ) == true then
rs.setBundledOutput("back", colors.black )
else
print ("its not 16")
end
Ridous #7
Posted 29 February 2012 - 07:08 PM
that's also calling nil o.o
Liraal #8
Posted 29 February 2012 - 07:11 PM
sorry didnt see that

local match = rs.getBundledInput("left") –you can use getBundledOutput as well

if colors.test(match, colors.white ) == true then
rs.setBundledOutput("back", colors.black )
else
print ("its not 16")
end
Luanub #9
Posted 29 February 2012 - 10:14 PM
You cant use, local match = rs.getBundledInput("left") with…. if colors.test(match, colors.white ) == true then

You want match to just == the side.

colors.test is used to test colors not redstone signals. So for it to work you would need some stuff like this in your code…

Spoiler

c = colors.combine( c , colors.red )

if colors.test( c , colors.white ) == true then
rs.setBundledOutput("back", colors.black )
else
print ("its not 16")
end
which would return its not 16

or

c = colors.combine( c , colors.white)

if colors.test( c , colors.white ) == true then
rs.setBundledOutput("back", colors.black )
else
print ("its not 16")
end
which would turn black on

I've tested this and it works.. Assuming your are checking to see if white is on the code should be something like..

local match = ("left")

if rs.testBundledInput(match, colors.white ) == true then
rs.setBundledOutput("back", colors.black )
else
print ("its not 16")
end


And to improve some i would do something like this, which will allow you to turn it on and off without affected any of the other signals you are sending out the back. To turn it off you just need to add a colors.subtract section.


local match = ("left")
c = colors.combine( c )

if rs.testBundledInput(match, colors.white ) == true then
c = colors.combine( c , colors.black )
rs.setBundledOutput("back", c )
else
print ("its not 16")
end


I fixed several errors in your factory scripting as well, here it is.. The main menu is huge I would make it smaller..

SpoilerFactory

--credit for the main menu build goes to Casper7526
--I ripped most of his tutorial code apart to do most of this.
--Mind the fact that this is a personal build and will request help if needed.
--I never used LUA before =p

--Current Version: Alpha.0 (Uncompleted Build)

--This program is ment to be run inside minecraft with the CC(ComputerCraft)
--mod. Outside of that this program does nothing.
--All feedback and switches are activated using the Laser mod for minecraft.
--along with Eloraam's RedPower2 mod for minecraft

function mainmenu()
while true do
term.clear()
term.setCursorPos(1,1)
print "-------------------------------------------------"
print "|				Factory Master Computer  Alpha 1		   |"
print "|								 Foreman: Ridous						   |"
print "-------------------------------------------------"
print "| 1. Engines																	 |"
print "| 2. Cooling																	 |"
print "| 3. Re-fuel																	 |"
print "| 4. Quarry																	   |"
print "| 5. Bedrock Breaker													 |"
print "| 6. Pumps																		 |"
print "| 7. Genorators														   |"
print "| 8. Anti-Creeper System										 |"
print "| 9. Factory Self-Destruct										 |"
print "| 0. Clock-out															 |"
print "|																						   |"
print "|																						   |"
print "|																						   |"
print "-------------------------------------------------"
-- currently Bedrock Breaker is just the name for my
-- cobble genorator which can output 15 stacks in 60
-- seconds.
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "0" then break end
if event == "char" and param1 == "1" then Engines() end
if event == "char" and param1 == "2" then Cooling() end
if event == "char" and param1 == "3" then Refuel() end
if event == "char" and param1 == "4" then Quarry() end
if event == "char" and param1 == "5" then BedrockBreaker() end
if event == "char" and param1 == "6" then Pumps() end
if event == "char" and param1 == "7" then Gens() end
if event == "char" and param1 == "8" then LaserDefecne() end
if event == "char" and param1 == "9" then SlefDestruct() end
end
end

function Engines()
while true do
term.clear()
term.setCursorPos(1,1)
shell.run( EngineData , onoff , match , gas75 , level , water , heatc )
-- above shell run will run EngineData and will send the variables for
-- onoff, match, gas75, level, water, and heatc
print "-------------------------------------------------"
print "|				Factory Master Computer  Alpha 1		   |"
print "|								 Foreman: Ridous						   |"
print "-------------------------------------------------"
print "|								   Engines									   |"
print "|																						   |"
print ("|						Currently			   "..onoff.."		|")
print "|																						   |"
print ("|		Current Number			 "..match.."	 |")
print ("|		Full Tank?						 "..gas75.."	 |")
print ("|		Water Level					   "..level.."	  |")
print ("|		Cooling System?		   "..water.."	  |")
print ("|		Heat Level						 "..heatc.."	 |")
print "|																						   |"
print "|		Turn off/on?					   [Y] [N]			   |"
print "|																						   |"
print "|																						   |"
print "-------------------------------------------------"
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "y" then
shell.run( EngineData , switch )
mainmenu()
end
if event == "char" and param1 == "n" then mainmenu() end
-- pressing "y" will run the switch function in EngineData to make it
-- turn off if its already on or turn it on if it was off and then send
-- you back to the main menu. Pressing "n" will just send you back to
-- to the main menu.
end
end

function Cooling()
while true do
term.clear()
term.setCursorPos(1,1)
shell.run( CoolingData, onoff , match , reser , level )
-- above shell run will run CoolingData and will send the variables for
-- onoff, match, reser, and level
print "-------------------------------------------------"
print "|				Factory Master Computer  Alpha 1		   |"
print "|								 Foreman: Ridous						   |"
print "-------------------------------------------------"
print "|								   Cooling									   |"
print "|																						   |"
print ("|						Currently			   "..onoff.."		|")
print ("|																						   |")
print ("|		Current Number			 "..match.."	 |")
print ("|		Full Reserves?			 "..reser.."	 |")
print ("|		Heat Level						 "..level.."	 |")
print "|																						   |"
print "|																						   |"
print "|																						   |"
print ("|		Turn off/on?					   [Y] [N]			   |")
print "|																						   |"
print "|																						   |"
print "-------------------------------------------------"
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "y" then
shell.run( CoolingData , switch )
mainmenu()
end
if event == "char" and param1 == "n" then mainmenu()
end
end
end

mainmenu()
Edited on 29 February 2012 - 09:39 PM
Ridous #10
Posted 03 March 2012 - 02:09 AM
For some reason I'm getting a nil error at line 4 o-o

Spoiler

--Message to Serene: This is so far prints the engine count. later will make "match"  equal to
--the number of sensors activated still.
--Engine counting code. can only count 15 max.
--Sector code located at SectorCounter_Buildv0.3
local match = rs.getBundledInput("front") --you can use getBundledOutput as well

rs.setBundledOutput("front",65535)
wait(2)
rs.setBundledOutput("front",0)
wait(2)
--65535 All
--0 None
if colors.test(match, colors.white ) == true then
print "0"
--rs.setBundledOutput("back", colors.black )
elseif colors.test(match, colors.orange ) == true then
print "1"
elseif colors.test(match, colors.magenta ) == true then
print "2"
elseif colors.test(match, colors.lightBlue ) == true then
print "3"
elseif colors.test(match, colors.yellow ) == true then
print "4"
elseif colors.test(match, colors.lime ) == true then
print "5"
elseif colors.test(match, colors.pink ) == true then
print "6"
elseif colors.test(match, colors.gray ) == true then
print "7"
elseif colors.test(match, colors.lightGray ) == true then
print "8"
elseif colors.test(match, colors.cyan ) == true then
print "9"
elseif colors.test(match, colors.purple ) == true then
print "10"
elseif colors.test(match, colors.blue ) == true then
print "11"
elseif colors.test(match, colors.brown ) == true then
print "12"
elseif colors.test(match, colors.green ) == true then
print "13"
elseif colors.test(match, colors.red ) == true then
print "14"
elseif colors.test(match, colors.black ) == true then
print "15"
else
match = "You have not yet to properly set the system. Try again."
print (match)
end
Espen #11
Posted 03 March 2012 - 02:14 AM
There is no wait() function. sleep() is what you're looking for.
MysticT #12
Posted 03 March 2012 - 02:15 AM
You are trying to call wait(), wich isn't defined. Use sleep() instead.
Ridous #13
Posted 03 March 2012 - 02:30 AM
thanks guys =D
Ridous #14
Posted 03 March 2012 - 08:14 PM
You think this is good or it can it be improved?
Also is there a way for to add the total engines after each time it calls the display function?


Spoiler

--Most run twice to get result. First run is bugged.
--Engine counting code. can only count 15 max.
--SectorCounter_Buildv0.3
--Computer # 3 - "Engine Sever"
--Rednet is a pending option to link to Computer # 1 - "Master Computer"


local path = ""
local side = ""
local match = ""

function start_test()

rs.setBundledOutput(side,65535)
print "Conducting test."
sleep(2)
rs.setBundledOutput(side,0)
print "Reviewing count."
sleep(2)
--65535 All
--0 None
end

function probe()

if colors.test(path, 1 ) == true then
match = 0
elseif colors.test(path, 2 ) == true then
match = 1
elseif colors.test(path, 4 ) == true then
match = 2
elseif colors.test(path, 8 ) == true then
match = 3
elseif colors.test(path, 16 ) == true then
match = 4
elseif colors.test(path, 32 ) == true then
match = 5
elseif colors.test(path, 64 ) == true then
match = 6
elseif colors.test(path, 128 ) == true then
match = 7
elseif colors.test(path, 256 ) == true then
match = 8
elseif colors.test(path, 512 ) == true then
match = 9
elseif colors.test(path, 1024 ) == true then
match = 10
elseif colors.test(path, 2048 ) == true then
match = 11
elseif colors.test(path, 4096 ) == true then
match = 12
elseif colors.test(path, 8192 ) == true then
match = 13
elseif colors.test(path, 16384 ) == true then
match = 14
elseif colors.test(path, 32768 ) == true then
match = 15
else
match = "You have not yet to properly set the system. Try again."
print (match)
end
end

function display()

path = rs.getBundledInput(side)
start_test()
probe()
print ("There are "..match.." on the "..side..".")
sleep(2)
end

side = "front"
display()
side = "left"
display()


current test setup structure pipes are standing in for the engines for now =p

Ridous #15
Posted 06 March 2012 - 03:17 AM
How do I make a table that will save two copies of its data in a text file every five minutes?
Also how to make a table in general, I can't read the code correctly? =x


Making a server that will count everything my quarries pick up and will backup all the info on files incase the first one is being used.
Also making it create a log of all materials extracted so I can have a log of what my factory is using. (that's for another server.)