7 posts
Posted 03 August 2012 - 10:13 PM
Well the title explains it, I want to add electricity to my worlds and computers will only turn on if its connected to a redstone current. I used this code to make the computer turn on if it is connected to redstone but not if its not.
if not redstone.getInput("bottom") then
os.shutdown()
else
if redstone.getInput("bottom") then
end end
thats exactly what I typed into the computer and it worked but after the computer turns on if I remove the redstone current to the computer it stays on. My question is how to I get it to turn off after it turns on and the current then gets broken.
By the way I put the code into startup.
1604 posts
Posted 03 August 2012 - 10:17 PM
You can use parallel to check for power on the background:
local function checkPower()
while true do
if not rs.getInput("bottom") then
os.shutdown()
end
os.pullEvent("redstone")
end
end
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
Not tested, but it should work.
1111 posts
Location
Portland OR
Posted 03 August 2012 - 10:18 PM
There's no real way to have a redstone signal turn on the computer. What you will need to do is have the computer sit in a loop where it does not progress or do anything but sleep until it gets a redstone signal.
while true do
if rs.getInput("bottom") then
break
else
sleep(.1)
end
end
:P/>/>
Edited on 03 August 2012 - 08:19 PM
7 posts
Posted 03 August 2012 - 10:28 PM
You can use parallel to check for power on the background:
local function checkPower()
while true do
if not rs.getInput("bottom") then
os.shutdown()
end
os.pullEvent("redstone")
end
end
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
Not tested, but it should work.
Thanks it worked perfectly so now if its on and I break the redstone it turns off till I fix the cable but at the top is says CraftOS 1.3 twice now but its not a big problem
7 posts
Posted 03 August 2012 - 10:43 PM
I dont want to break anything so I was wondering if this would work if I added
rednet.open"right" to it cause I like to have the modem automatically turn on?
nevermind got it to work
Edited on 03 August 2012 - 09:18 PM
1604 posts
Posted 03 August 2012 - 11:20 PM
Here you go:
local function checkPower()
while true do
if not rs.getInput("bottom") then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
Now it clears the screen before starting the new shell, so it doesn't write "CraftOS 1.X" twice, and opens the right side for rednet.
You can add anything you want to it, just do it before the parallel call, or it won't do it until it shuts down (unless that's what you want).
7 posts
Posted 03 August 2012 - 11:42 PM
Here you go:
local function checkPower()
while true do
if not rs.getInput("bottom") then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
Now it clears the screen before starting the new shell, so it doesn't write "CraftOS 1.X" twice, and opens the right side for rednet.
You can add anything you want to it, just do it before the parallel call, or it won't do it until it shuts down (unless that's what you want).
thanks alot and it says im clueless actually I know a bit about lua cause I played roblox since I was 10 and did some scripting on it
7 posts
Posted 03 August 2012 - 11:49 PM
Here you go:
local function checkPower()
while true do
if not rs.getInput("bottom") then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
Now it clears the screen before starting the new shell, so it doesn't write "CraftOS 1.X" twice, and opens the right side for rednet.
You can add anything you want to it, just do it before the parallel call, or it won't do it until it shuts down (unless that's what you want).
thanks alot and it says im clueless actually I know a bit about lua cause I played roblox since I was 10 and did some scripting on it
By the way it still says CraftOS twice
1604 posts
Posted 04 August 2012 - 12:07 AM
It shouldn't, since it clears the screen before starting the new shell. Have you added the lines to clear the screen?
7 posts
Posted 04 August 2012 - 12:09 AM
It shouldn't, since it clears the screen before starting the new shell. Have you added the lines to clear the screen?
Yeah I pratically copied and pasted the new code you gave me :P/>/>
53 posts
Location
London, UK
Posted 04 August 2012 - 07:53 AM
actually I know a bit about lua cause I played roblox since I was 10 and did some scripting on it
Same here, man.
45 posts
Location
Wisconsin
Posted 16 August 2012 - 07:40 PM
How would you change this from checking for a normal redstone input from the bottom as it is now to checking for a certain color being active via bundeledcable directly attached to the computer
11 posts
Posted 16 August 2012 - 08:09 PM
How would you change this from checking for a normal redstone input from the bottom as it is now to checking for a certain color being active via bundeledcable directly attached to the computer
I'm guessing it would be something like this:
let the colour of wire be N
local function checkPower() while true do if not rs.getBundledInput("bottom")==<decimal representation of the colour goes here> then os.shutdown() end os.pullEvent("redstone") endendterm.clear()term.setCursorPos(1, 1)rednet.open("right")parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)os.shutdown()I haven't tested this but I assume that's what you would do…
45 posts
Location
Wisconsin
Posted 16 August 2012 - 09:17 PM
How would you change this from checking for a normal redstone input from the bottom as it is now to checking for a certain color being active via bundeledcable directly attached to the computer
I'm guessing it would be something like this:
let the colour of wire be N
local function checkPower() while true do if not rs.getBundledInput("bottom")==<decimal representation of the colour goes here> then os.shutdown() end os.pullEvent("redstone") endendterm.clear()term.setCursorPos(1, 1)rednet.open("right")parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)os.shutdown()I haven't tested this but I assume that's what you would do…
im slighly confused,
1: where do i find the decimal representaions of each color
2: do i incule the double == and brackets< .. >
3790 posts
Location
Lincoln, Nebraska
Posted 16 August 2012 - 09:26 PM
45 posts
Location
Wisconsin
Posted 16 August 2012 - 09:28 PM
http://computercraft...tle=Colors_(API)
That will give you all of the color representations.
Colors (APIThere is currently no text in this page. You can
search for this page title in other pages,
search the related logs, or
edit this page.
3790 posts
Location
Lincoln, Nebraska
Posted 16 August 2012 - 09:35 PM
Oops, I forgot, the copy/paste of links here is a little derpy. Here:
This should work
45 posts
Location
Wisconsin
Posted 16 August 2012 - 09:43 PM
local function checkPower()
while true do
if not rs.getBundledInput("bottom")==<2> then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
im geting a unexpected symbol on line 3
3790 posts
Location
Lincoln, Nebraska
Posted 16 August 2012 - 09:45 PM
There should not be a <> around 2. It is a number. The line should read like this:
if not rs.getBundledInput("bottom") == 2 then
45 posts
Location
Wisconsin
Posted 16 August 2012 - 09:48 PM
fixed it, no errors at all however it simply doesn't work i have a bundled cable plugged into the bottom
it makes no difference if orange (2) is on or not the computer is still accessible and unchanged
3790 posts
Location
Lincoln, Nebraska
Posted 16 August 2012 - 09:52 PM
Does the cable terminate AT the bottom of the computer, or does it just run ON the bottom? Bundled cables must terminate at computers.
I this is not the case, then I'll have to check the code when I get home later. Or maybe some of the other pros could chime in? :(/>/>
45 posts
Location
Wisconsin
Posted 16 August 2012 - 09:58 PM
im not sure what you mean by terminate, but the cable is connected properly as there are other programs on the computer making use of its other colors
edit: yeah just figured out what you meant, it terminates at the bottom
3790 posts
Location
Lincoln, Nebraska
Posted 16 August 2012 - 10:07 PM
OK, I'll have to check it out later then… I'm at work, and not in "Code mode"
1604 posts
Posted 16 August 2012 - 11:54 PM
Using rs.testBundledInput and the colors api is easier, this should work:
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
45 posts
Location
Wisconsin
Posted 17 August 2012 - 02:42 PM
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange)
and
if not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
1: will this work?
2: why do i get a unexpected symbol on line 5
11 posts
Posted 17 August 2012 - 03:59 PM
I think it should be:
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) and not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
45 posts
Location
Wisconsin
Posted 17 August 2012 - 04:08 PM
I think it should be:
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) and not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end
os.pullEvent("redstone")
end
end
term.clear()
term.setCursorPos(1, 1)
rednet.open("right")
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
os.shutdown()
thanks dude, do you know if i wanted to add more sides if i could simply just append more of them like you did with back?