45 posts
Location
Wisconsin
Posted 17 August 2012 - 02:33 PM
1: Checks for electricity input via bundled cable(orange) and if its on it turns on the machine if not it goes dark
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()
2: based on computer ID it runs a program if electricity is on (this isnt real code obviously, just me explaining)
Somthing Like This
if
computerid ( 5000 < 5100 )
then
shell.run(5000)
elseif
computerid ( 5200 < 5700 )
then
shell.run(5500)
else
shell.run("/rom/programs/shell")
3: how to force a id upon a computer
997 posts
Location
Wellington, New Zealand
Posted 17 August 2012 - 03:08 PM
1: Checks for electricity input via bundled cable(orange) and if its on it turns on the machine if not it goes dark
Your code is right there, the problem is?
2: based on computer ID it runs a program if electricity is on (this isnt real code obviously, just me explaining)
If you translate that "not real code" into real code, then it will work.
3: how to force a id upon a computer
You can't.
45 posts
Location
Wisconsin
Posted 17 August 2012 - 03:18 PM
1: Checks for electricity input via bundled cable(orange) and if its on it turns on the machine if not it goes dark
Your code is right there, the problem is?
2: based on computer ID it runs a program if electricity is on (this isnt real code obviously, just me explaining)
If you translate that "not real code" into real code, then it will work.
3: how to force a id upon a computer
You can't.
for 1: i know it works however i believe it would need to be adapted slightly to Handel the next step instead of simply running the shell thingy
for 2: cant figure it out, have already tried looking stuff up
for 3: Awww
686 posts
Posted 17 August 2012 - 03:41 PM
Why don't you ask the people who gave you the code in the first place?
45 posts
Location
Wisconsin
Posted 17 August 2012 - 03:57 PM
Why don't you ask the people who gave you the code in the first place?
i got that code from another thread
45 posts
Location
Wisconsin
Posted 17 August 2012 - 08:10 PM
I just thought of something, because u cant force ids
would it be possible instead of using the computer ids to use the labels
so like if computer label is 5001
it would run the program that runs if the label is between 5000 < 5100 or somthing
i don't even know if you can make it check its label like that
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 08:13 PM
You can use os.computerID() to check the ID of the current computer, and use that result to use your code. Like this:
local id = os.computerID()
if id== 5 then
--do stuff if computer # 5
elseif id == 10 then
--do stuff if computer # 10
end
EDIT: You want some of the functions available in the
OS API.
Edited on 17 August 2012 - 06:15 PM
45 posts
Location
Wisconsin
Posted 17 August 2012 - 08:17 PM
You can use os.computerID() to check the ID of the current computer, and use that result to use your code. Like this:
local id = os.computerID()
if id== 5 then
--do stuff if computer # 5
elseif id == 10 then
--do stuff if computer # 10
end
EDIT: You want some of the functions available in the
OS API.
is there anyway to utiilize labels like i posted above. the reason i wanted to do this in the first place is because of the annoyance of going to every computer checking the id then changing each startup file in every local folder respectivly and if i cant set computer id, maby i can set labels like a id.
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 08:19 PM
Yes. That's also in the OS API. All you use instead is os.getComputerLabel() instead of os.computerID()
45 posts
Location
Wisconsin
Posted 17 August 2012 - 08:21 PM
ok i think i can manage that however you showed how to check a single id how could i do it so it checks if the id or label is between a numeric range like 100 - 200
or can u have 2+ computers both labeled the same label?
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 08:25 PM
Yeah. You can check by doing this:
local id = os.computerID()
if id < 5 then
--do stuff if the id is less than 5
elseif id > 5 then
--do stuff if id is greater than 5
end
You can use lots of operators instead of just < or >. If you are interested in some more advanced math operations, check out
HERE
45 posts
Location
Wisconsin
Posted 17 August 2012 - 08:34 PM
so like this?
local id = os.getComputerLabel()
if id >= 100 and id <= 500 then
-- do whatever
elseif id >=501 and id <=1000 then
- do stuff
end
is that how you do it with between?
also the local id = the os thing
thats were we are defining the term id as the computer label right?
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 08:40 PM
If you are trying to compare labes, no. Labels are strings, and are called back to by using quotations (" "). Your cannot compare using numerical code unless using the computer IDs, which are returned as numbers. If you want to compare with Labels, do this:
local label = os.getComputerLabel()
if label == "Label" then--now we must compare it absolutely equal(==), and cannot use less than or greater than.
--do stuff if label == "Label"
elseif not label == "Label" then --anything other than the label "Label"; can also use if label ~= "Label"
--do stuff if not "Label"
end
45 posts
Location
Wisconsin
Posted 17 August 2012 - 08:45 PM
1: there isnt a way to force a computer to have a certain id right?
2: if my labels are all numeric values is there anyway to convert the string into something that can be interpreted as a number?
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 08:48 PM
1. No, sorry.
2. You want tonumber()
example:
local id = tonumber(os.getComputerLabel()) --this turns what would be a string into a number, if possible.
45 posts
Location
Wisconsin
Posted 17 August 2012 - 11:08 PM
1. No, sorry.
2. You want tonumber()
example:
local id = tonumber(os.getComputerLabel()) --this turns what would be a string into a number, if possible.
I have this setup
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()
local id = tonumber(os.getComputerLabel()) --this turns what would be a string into a number, if possible.
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("/rom/programs/time")
else
shell.run("/rom/programs/shell")
end
The Electiricity check works fine however i made a computer set its label to 101 and confirmed it was set by checking the labels file. when the computer was started with electricity on it simply started like default and didn't run the "test2" program as it should.
what did i do wrong
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 11:10 PM
Is test2 something you added to the ROM manually? Or did you just do edit test2 to create that program? If so, then test2 will just be in shell.run("test2").
45 posts
Location
Wisconsin
Posted 17 August 2012 - 11:27 PM
Is test2 something you added to the ROM manually? Or did you just do edit test2 to create that program? If so, then test2 will just be in shell.run("test2").
this is in a multiplayer environment "test2" is a program in the ROM i added via external text editor so its listed in the programs directory of every computer
3790 posts
Location
Lincoln, Nebraska
Posted 17 August 2012 - 11:33 PM
I beleive you may need the parallel function at the end, but I'm not sure. Without being able to test, I can't be positive. I might be able to check later tonight.
45 posts
Location
Wisconsin
Posted 17 August 2012 - 11:40 PM
This causes the computer to simply remain black and unusable no mater what the electricity state is, it doesn't even flicker on then off quickly on startup like it usualy does with the electricity check
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")
os.shutdown()
local id = tonumber(os.getComputerLabel()) --this turns what would be a string into a number, if possible.
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("/rom/programs/time")
else
shell.run("/rom/programs/shell")
end
parallel.waitForAny(checkPower, function() shell.run("/rom/programs/shell") end)
45 posts
Location
Wisconsin
Posted 18 August 2012 - 12:01 AM
I beleive you may need the parallel function at the end, but I'm not sure. Without being able to test, I can't be positive. I might be able to check later tonight.
what did i do wrong?
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 02:36 AM
I think I got what you are wanting. Check the code here with notes:
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) and not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end
end
end
function checkID() --we need to make this a function so we can test it.
--Unless you want this to run before shutdown?
--if so, just call checkID() before os.reboot()
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
rednet.open("right") --no idea what this is for. Future use perhaps?
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAny(checkPower,checkID) --you need your parallel function at the end of your program in this instance
os.reboot() --if parallel finds any function has completed, it will reboot
I had to wait until I was at home to test this code. Should work like you wanted, but I am not sure what you are trying to accomplish with this. What do you need the IDs for?
45 posts
Location
Wisconsin
Posted 18 August 2012 - 02:39 AM
I had to wait until I was at home to test this code. Should work like you wanted, but I am not sure what you are trying to accomplish with this. What do you need the IDs for?
I am working on somthing that has over 1000 "literaly" computers and a bunch of them need to run the same program on start, instead of me digging through the individual computer id folders i thought it would be easier to do it this way
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 02:40 AM
What in God's name are you doing with over 1000 computers?????
45 posts
Location
Wisconsin
Posted 18 August 2012 - 02:42 AM
I think I got what you are wanting. Check the code here with notes:
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) and not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end
end
end
function checkID() --we need to make this a function so we can test it.
--Unless you want this to run before shutdown?
--if so, just call checkID() before os.reboot()
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
rednet.open("right") --no idea what this is for. Future use perhaps?
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAny(checkPower,checkID) --you need your parallel function at the end of your program in this instance
os.reboot() --if parallel finds any function has completed, it will reboot
I had to wait until I was at home to test this code. Should work like you wanted, but I am not sure what you are trying to accomplish with this. What do you need the IDs for?
it was black for about 10 seconds then errored with
parallel:22: startup:4: Too log without yeilding
45 posts
Location
Wisconsin
Posted 18 August 2012 - 02:46 AM
What in God's name are you doing with over 1000 computers?????
im working with a team to create somthing we are naming [The Siege] it is a brand new gamemode + map series for minecraft. it is massively multilayer (100+ player) and completely overhauls minecraft. we are using computercraft as part of it, one of the few publicly available mods we are using that isn't made by us, and before you ask if we can make those mods and overhaul minecraft why can't we do this. The people i have working on that aspect of the project have their hands full.
The release is set for mid-November
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 02:47 AM
My mistake. Forgot a 'break' in there…
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) and not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end break
end
end
function checkID()
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
rednet.open("right")
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAny(checkPower,checkID)
os.shutdown()
45 posts
Location
Wisconsin
Posted 18 August 2012 - 02:51 AM
My mistake. Forgot a 'break' in there…
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
if not rs.testBundledInput("bottom", colors.orange) and not rs.testBundledInput("back", colors.orange) then
os.shutdown()
end break
end
end
function checkID()
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
rednet.open("right")
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAny(checkPower,checkID)
os.shutdown()
When electiricity is on it is simply black screening
When i turn it off and click the computer to check it i see that same error flash once and then goes black
45 posts
Location
Wisconsin
Posted 18 August 2012 - 02:58 AM
My mistake. Forgot a 'break' in there…
it seems the electicity check broke somwere, as it black screens if the computer has power
and does what its supposed to if it doesnt
however the error is still there
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 03:21 AM
It's because you have the os.shutdown() at the end. If you replace that with os.reboot(), it will constantly restart the program. Be warned though… over 1000 computers doing that all at one time will lag your computer to hell… I tested that with different variables in place of your commands, and the syntax is correct if you want it to check once. To have them all check at the same time, while also checking for power, during an extended period of time is quite a task. This might do what you're looking to do on a grander scale. Waiting for an event does not kill a server.
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
event, p1 = os.pullEvent()
if event == "redstone" then
if rs.testBundledInput("back", colors.orange) and rs.getBundledInput("bottom", colors.orange) then
break
end
end
end
end
function checkID()
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
rednet.open("right")
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAll(checkPower,checkID)
os.shutdown()
45 posts
Location
Wisconsin
Posted 18 August 2012 - 03:32 AM
It's because you have the os.shutdown() at the end. If you replace that with os.reboot(), it will constantly restart the program. Be warned though… over 1000 computers doing that all at one time will lag your computer to hell… I tested that with different variables in place of your commands, and the syntax is correct if you want it to check once. To have them all check at the same time, while also checking for power, during an extended period of time is quite a task. This might do what you're looking to do on a grander scale. Waiting for an event does not kill a server.
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
event, p1 = os.pullEvent()
if event == "redstone" then
if rs.testBundledInput("back", colors.orange) and rs.getBundledInput("bottom", colors.orange) then
break
end
end
end
end
function checkID()
if id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
rednet.open("right")
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAll(checkPower,checkID)
os.shutdown()
with the os releoad changed it results in
parallel :22: startup:13: attempt to compare nil with number
Also the electricity check doesn't work at all now.
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 04:18 AM
You forgot to label your computer.
45 posts
Location
Wisconsin
Posted 18 August 2012 - 04:47 AM
You forgot to label your computer.
is there a way that if it doesnt have a label it will still do the electricity check, them boot normaly
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 06:04 AM
Sure, just add
elseif id == nil then
to it.
45 posts
Location
Wisconsin
Posted 18 August 2012 - 12:42 PM
Sure, just add
elseif id == nil then
to it.
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
event, p1 = os.pullEvent()
if event == "redstone" then
if rs.testBundledInput("back", colors.orange) and rs.getBundledInput("bottom", colors.orange) then
break
end
end
end
end
function checkID()
if id == nil then
shell.run("rom/programs/shell")
elseif id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAll(checkPower,checkID)
os.reboot()
the runing of porgrams based on ID / label works fine now, however the electricity check doesnt work at all it simply ignores it and turns on nomater what
3790 posts
Location
Lincoln, Nebraska
Posted 18 August 2012 - 03:17 PM
Are you intending to Go around and turn on all 1000 computers manually? Otherwise, there's no real way to have them turn on when a redstone current is applied. If you want them to be inert until a signal is applied, add os.shutdown() before the break.
local id = tonumber(os.getComputerLabel())
local function checkPower()
while true do
event, p1 = os.pullEvent()
if event == "redstone" then
if not rs.testBundledInput("back", colors.orange) and not rs.getBundledInput("bottom", colors.orange) then
--needing not statements of making inert until signal
os.shutdown() break
end
end
end
end
function checkID()
if id == nil then
shell.run("rom/programs/shell")
elseif id >= 100 and id <= 500 then
shell.run("/rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
term.clear()
term.setCursorPos(1, 1)
parallel.waitForAll(checkPower,checkID)
os.reboot()
45 posts
Location
Wisconsin
Posted 18 August 2012 - 04:00 PM
Are you intending to Go around and turn on all 1000 computers manually? Otherwise, there's no real way to have them turn on when a redstone current is applied. If you want them to be inert until a signal is applied, add os.shutdown() before the break.
that changed nothing. the electricity check is still not working any more
The electricity check is supposed to make it so that if there is no power input the computer will not turn on as well as if the power turns off mid session so does the computer
you actualy helped me get that working over here
http://www.computercraft.info/forums2/index.php?/topic/3114-need-help-adding-electricity-to-computers/
45 posts
Location
Wisconsin
Posted 18 August 2012 - 04:02 PM
also the reason behind the id based program start is so on certain machines when a person right clicks it to turn it on it turns on with the appropriate program running already
3790 posts
Location
Lincoln, Nebraska
Posted 19 August 2012 - 12:19 AM
This will keep the computer from being used at all while you do not have power. As soon as you have power, it will check fot he ID. If the ID matches, it will run your program. However, once you are in that new program, you have to make something in that new program check for power state, and shut down from there. This startup program cannot do that for you.
local id = tonumber(os.getComputerLabel())
local p1 = rs.testBundledInput("back", colors.orange)
local p2 = rs.testBundledInput("bottom", colors.orange)
function checkID()
if id >= 100 and id <= 500 then
shell.run("rom/programs/test2")
elseif id >=501 and id <=1000 then
shell.run("rom/programs/time")
else
shell.run("rom/programs/shell")
end
end
function pCheck()
if p1 and p2 then return true
else return false
end
end
local check = pCheck()
while check do
local event = os.pullEvent()
if event == "redstone" then
checkID()
if check == false then break end
end
end
while not check do
os.shutdown()
end