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

Fortress Control

Started by shif, 20 February 2012 - 03:57 AM
shif #1
Posted 20 February 2012 - 04:57 AM
heres a small program i developed to control my fortress, it uses wireless redstone blocks, it has 6 services and the program manage their toggles, pretty basic



shell.run("clear");

-- Creates 3 arrays, s to store the constant of each color, o to store the toggles and sn to store the names of the toggles
s = {colors.white, colors.red, colors.lightBlue, colors.yellow, colors.blue, colors.black};
o = {"off", "off", "off", "off", "off", "off"};
sn = {"Service 1", "Service 2", "Service 3", "Service 4", "Service 5", "Service 6"};

-- some placeholders for later
cs = 1;
co = "off";

-- master color variable, the sum of all the color constants of services that are on will be stored here
master = 0;

while true do
shell.run("clear");

-- reset master
master = 0;

print("/// Fort Systems Controller ///\n");

-- for loop to check if a toggle is on and if it is then it adds the color value to the master variable
for i=1, 6 do
-- the status variable will store "on" or "off", i use it to convert "on" to "on " so the text doesnt move
status = o[i];
if(o[i] == "on") then
status = status.." ";
master = master + s[i];
end
-- this is what turns each cable on, based on the value of the master variable it decides which cables to turn on
rs.setBundledOutput("bottom", master);
-- this prints each of the services and their states
print(i.." - "..status.." - "..sn[i]);
end

-- here it asks for what service to toggle, if the number is not in the list it asks again
sValid = true;
while sValid do
write("\nSelect a service to toggle: ");
cs = read();
-- this took me some painful moments of troubleshooting, if you dont convert what you read() and then try to use it to point inside an array it will point to different data, example: not calling tonumber(cs) and then doing i[cs] would do i["3"] instead of i[3]
cs = tonumber(cs);
if((cs == 1) or (cs == 2) or (cs == 3) or (cs == 4) or (cs == 5) or (cs == 6)) then
sValid = false;
else
print("Invalid Service");
end
end

--here it toggles the service, if its on it turns it off and vice versa
co = o[cs];
if(co == "on") then
o[cs] = "off";
else
o[cs] = "on";
end

end

This is the wiring that go below the computer
[attachment=26:1.jpg]

Another Angle
[attachment=27:2.jpg]

This is how it looks covered
[attachment=28:3.jpg]
rockymc #2
Posted 20 February 2012 - 10:35 AM
You are using 1.3pr2?
FuzzyPurp #3
Posted 20 February 2012 - 01:51 PM
You are using 1.3pr2?

Obviously not, otherwise he'd be using modems and turtles ;)/>/>
Evis #4
Posted 01 March 2012 - 09:57 AM
Just tried this on 1.3; no go - the output doesn't work. I cannot get it to output a rs signal even though the interface works fine.

Any tips for getting this to work …and for all 16 colors?

I see a vast array of uses for these types of programs, and particularly like the way you have the GUI laid out / functioning.
Wolvan #5
Posted 01 March 2012 - 08:22 PM
Just tried this on 1.3; no go - the output doesn't work. I cannot get it to output a rs signal even though the interface works fine.

Any tips for getting this to work …and for all 16 colors?

I see a vast array of uses for these types of programs, and particularly like the way you have the GUI laid out / functioning.
You can try to send commands with rednet to another wireless modem PC that outputs a redstone-signal if the command is right. I could help you
Timonator #6
Posted 01 March 2012 - 11:08 PM
you have to load redpower before computercraft else the bundled cable output is bugged. Just put an a before redpower.
Evis #7
Posted 01 March 2012 - 11:21 PM
you have to load redpower before computercraft else the bundled cable output is bugged. Just put an a before redpower.

Got it! thanks. I actually had to add "A1" instead of "A" - when I did that, it started working.

Appreciate the offer for help. How you wanna do this?
francogp #8
Posted 02 March 2012 - 04:33 AM
you have to load redpower before computercraft else the bundled cable output is bugged. Just put an a before redpower.

Excuse my ignorance, how do you change the load order?
Evis #9
Posted 02 March 2012 - 06:25 AM
you have to load redpower before computercraft else the bundled cable output is bugged. Just put an a before redpower.

Excuse my ignorance, how do you change the load order?

For the server go to /jar/mods and rename redpower-all-2.0p4d-b1.1R3.zip to Aredpower-all-2.0p4d-b1.1R3.zip
francogp #10
Posted 02 March 2012 - 06:42 AM
you have to load redpower before computercraft else the bundled cable output is bugged. Just put an a before redpower.

Excuse my ignorance, how do you change the load order?

For the server go to /jar/mods and rename redpower-all-2.0p4d-b1.1R3.zip to Aredpower-all-2.0p4d-b1.1R3.zip

Thanks!, this problem is only for server side?
pcmaster160 #11
Posted 02 March 2012 - 11:02 PM
there are sphax textures for computercraft btw :unsure:/>/>
Evis #12
Posted 04 March 2012 - 07:06 AM
you have to load redpower before computercraft else the bundled cable output is bugged. Just put an a before redpower.

Excuse my ignorance, how do you change the load order?

For the server go to /jar/mods and rename redpower-all-2.0p4d-b1.1R3.zip to Aredpower-all-2.0p4d-b1.1R3.zip

Thanks!, this problem is only for server side?

I think it only effects servers hosted on Linux. When I was having the trouble my SP was working fine.

Now I'm on the hunt for a program similar to this one, that lets me select a side, and manage 16 colors out of that bundle. I tried to add to.modify this, but butchered it.
Evis #13
Posted 04 March 2012 - 08:10 AM
Ok I got 16 services (kinda) working;

If ya don't mind, Shif…


-- Original by Shif
-- Edit by Evis v.03
-- Svc 7 Doesn't Work

shell.run("clear");
-- Creates 3 arrays, s to store the constant of each color, o to store the toggles and sn to store the names of the toggles
s = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black};
o = {"off", "off", "off", "off", "off", "off", "off", "off", "off", "off", "off", "off", "off", "off", "off", "off"};
sn = {"Service 1", "Service 2", "Service 3", "Service 4", "Service 5", "Service 6", "Service 7", "Service 8", "Service 9", "Service 10", "Service 11", "Service 12", "Service 13", "Service 14", "Service 15", "Service 16"};
-- some placeholders for later
cs = 1;
co = "off";
-- master color variable, the sum of all the color constants of services that are on will be stored here
master = 0;
while true do
shell.run("clear");
-- reset master
master = 16;
print("/// Fort Systems Controller ///n");
-- for loop to check if a toggle is on and if it is then it adds the color value to the master variable
for i=1, 16 do
-- the status variable will store "on" or "off", i use it to convert "on" to "on " so the text doesnt move
status = o[i];
if(o[i] == "on") then
status = status.." ";
master = master + s[i];
end
-- this is what turns each cable on, based on the value of the master variable it decides which cables to turn on
redstone.setBundledOutput("top", master);
-- this prints each of the services and their states
print(i.." - "..status.." - "..sn[i]);
end
-- here it asks for what service to toggle, if the number is not in the list it asks again
sValid = true;
while sValid do
write("nSelect a service to toggle: ");
cs = read();
-- this took me some painful moments of troubleshooting, if you dont convert what you read() and then try to use it to point inside an array it will point to different data, example: not calling tonumber(cs) and then doing i[cs] would do i["3"] instead of i[3]
cs = tonumber(cs);
if((cs == 1) or (cs == 2) or (cs == 3) or (cs == 4) or (cs == 5) or (cs == 6) or (cs == 7) or (cs == 8) or (cs == 9) or (cs == 10) or (cs == 11) or (cs == 12) or (cs == 13) or (cs == 14) or (cs == 15) or (cs == 16)) then
sValid = false;
else
print("Invalid Service");
end
end
--here it toggles the service, if its on it turns it off and vice versa
co = o[cs];
if(co == "on") then
o[cs] = "off";
else
o[cs] = "on";
end
end

Service 7 is throwing a arithmetic error; any ideas?

control16:34: attempt to perform arithmetic 'add' on nil


Fixed the above error (spelling) but having a new error where 5 & 6 are inverted signals. …hmm
Timonator #14
Posted 07 March 2012 - 12:07 AM
Is it possible to send a pulse through a bundled cable :unsure:/>/>. I tried putting them on and off with a sleep in between but then my whole program is sleeping.
Liraal #15
Posted 07 March 2012 - 06:58 AM
try like:
while os.pullEvent()~="timer" do
rs.setBundledOutput('back", colors.combine(colors.lime, colors.red))
os.startTimer(3)
local a=os.pullEvent()
while a~="timer" do a=os.pullEvent() end
rs.setBundledOutput("back", colors.red)
Timonator #16
Posted 07 March 2012 - 10:13 PM
So this is what I have. The first item is to switch light. Then the loop with 2-7 is for my farming banks and they just need to pulse whenever I chooste them

shell.run("clear");
-- Creates 3 arrays, s to store the constant of each color, o to store the toggles and sn to store the names of the toggles
s = {colors.black, colors.pink, colors.white, colors.cyan, colors.yellow, colors.lime, colors.gray};
o = {"Uit", "Uit", "Uit", "Uit", "Uit", "Uit", "Uit"};
sn = {"Verlichting", "Farmbank 1", "Farmbank 2", "Farmbank 3", "Farmbank 4", "Farmbank 5", "Farmbank 6"};
-- some placeholders for later
cs = 1;
co = "off";
-- master color variable, the sum of all the color constants of services that are on will be stored here
master = 0;
while true do
shell.run("clear");
-- reset master
master = 0;
print("Sugarcane farmingcontroller");
print("------------------------------n");
print("Verlichting:n")
-- forloop verlichting
-- for loop Licht 1 --
for i=1, 1 do
status = o[i];
if(o[i] == "Aan") then
status = status.." ";
master = master + s[i];
end
rs.setBundledOutput("bottom", master);
print(i.." - "..sn[i].." - "..status);
end
print("n");
print("Farmingbanken:n");
--forloop farmingbanken
for i=2, 7 do
status = o[i];
if(o[i] == "Aan") then
status = status.." ";
master = master + s[i];
end
rs.setBundledOutput("bottom", master);
print(i.." - "..sn[i].." - "..status);
end
-- here it asks for what service to toggle, if the number is not in the list it asks again
sValid = true;
while sValid do
write("nMaak een keuze: ");
cs = read();
-- this took me some painful moments of troubleshooting, if you dont convert what you read() and then try to use it to point inside an array it will point to different data, example: not calling tonumber(cs) and then doing i[cs] would do i["3"] instead of i[3]
cs = tonumber(cs);
if((cs == 1) or (cs == 2) or (cs == 3) or (cs == 4) or (cs == 5) or (cs == 6) or (cs == 7)) then
sValid = false;
else
print("Optie niet beschikbaar");
end
end
--here it toggles the service, if its on it turns it off and vice versa
co = o[cs];
if(co == "Aan") then
o[cs] = "Uit";
else
o[cs] = "Aan";
end
end