while true do
local side = {"top", "bottom", "right", "left", "back", "front"}
local peripheralType = {"modem", "computer", "turtle", "drive"}
local intrusionTest = peripheral.getType( "side" )
if intrusionTest == peripheralType then
if intusionTest == side[5] and peripheralType[1] then
sleep(0.2)
else
bank.lock()
end
else
sleep(0.2)
end
end
[HELP]
#1
Posted 04 December 2012 - 09:38 AM
#2
Posted 04 December 2012 - 09:53 AM
#3
Posted 04 December 2012 - 09:55 AM
Describe the desired behavior of this program, I can't quite figure out what you're trying to do. Do you want to exclude a modem on the back from being considered an intruder?
Edited by ChunLing, 04 December 2012 - 09:58 AM.
#4
Posted 04 December 2012 - 01:14 PM
ChunLing, on 04 December 2012 - 09:55 AM, said:
Describe the desired behavior of this program, I can't quite figure out what you're trying to do. Do you want to exclude a modem on the back from being considered an intruder?
It's supposed to be password locked(it is not a vulgar lock though
Thanks
crackroach
Here is the full code(it's WIP by the way and it's also a 'dofile')
Edited by crackroach, 04 December 2012 - 02:32 PM.
#5
Posted 04 December 2012 - 03:56 PM
Here's something quick, see what you can do with it. First, a function to use to check for prohibited peripherals:
local function intrusionTest()
local prohibit = {"computer","turtle","drive"}
for k,v in pairs(rs.getSides()) do
for i = 1,#peripheralType do
if peripheral.getType(v) == prohibit[i] then return v,prohibit[i] end
end
end
return nil end
It should scan for peripherals matching the types in the prohibit list. If it finds one, it returns the side and the type found. It only need to find one to return. Otherwise it returns nil.Then we call this somewhere and use the result to decide to do something. Like:
if intrusionTest() then bank.lock() end
Or you can assign some variables to hold the returns and check them, if you allow those peripherals in some places and not others...though what the side has to do with it I don't know.
#6
Posted 04 December 2012 - 04:17 PM
ChunLing, on 04 December 2012 - 03:56 PM, said:
Here's something quick, see what you can do with it. First, a function to use to check for prohibited peripherals:
local function intrusionTest()
local prohibit = {"computer","turtle","drive"}
for k,v in pairs(rs.getSides()) do
for i = 1,#peripheralType do
if peripheral.getType(v) == prohibit[i] then return v,prohibit[i] end
end
end
return nil end
It should scan for peripherals matching the types in the prohibit list. If it finds one, it returns the side and the type found. It only need to find one to return. Otherwise it returns nil.Then we call this somewhere and use the result to decide to do something. Like:
if intrusionTest() then bank.lock() end
Or you can assign some variables to hold the returns and check them, if you allow those peripherals in some places and not others...though what the side has to do with it I don't know.
Thanks, it's pretty comprehensive. I thought about the modem problem and i came to the conclusion that only computer, turtle and drive can be harmful, so your example is functional. I guess the side has nothing to do with anything now, i wanted to put only one modem in the back, but the problem is solved.
I need an explanation for something though: if i put that function in a 'dofile' will it work? and that function should be a while loop in order to scan every second or so, right?
#7
Posted 04 December 2012 - 09:25 PM
Given that this needs to run so often, you might want to define prohibit outside the function so it doesn't have to be reallocated each time. Though that's really a minor issue until you get up into running it hundreds of times a second.
#8
Posted 05 December 2012 - 04:26 AM
ChunLing, on 04 December 2012 - 09:25 PM, said:
Given that this needs to run so often, you might want to define prohibit outside the function so it doesn't have to be reallocated each time. Though that's really a minor issue until you get up into running it hundreds of times a second.
Thanks for your help
#9
Posted 05 December 2012 - 10:41 AM
#10
Posted 05 December 2012 - 06:24 PM
ChunLing, on 05 December 2012 - 10:41 AM, said:
#11
Posted 05 December 2012 - 06:41 PM
But let's do it as a parallel friendly function.
local function intrusionTest()
local prohibit = {"computer","turtle","drive"}
while true do
os.pullEvent("peripheral")
for k,v in pairs(rs.getSides()) do
for i = 1,#peripheralType do
if peripheral.getType(v) == prohibit[i] then return v,prohibit[i] end
end
end
end
end
Now the function only ever ends if it finds a prohibited device, as long as it doesn't it just waits for a peripheral event and checks again. Note that this solves a problem I mentioned earlier, in that the local declaration of prohibit doesn't have to be repeated every time the detection loop runs, so there's that.Normally, if I were writing a program of this sort, I'd try to make an os.pullEvent loop the heart of the program. That would maximize the amount of control I'd have over everything. It also tends to mean that you have to write all your own input functions, though. So a bit of a hassle, if the function above will work.
#12
Posted 05 December 2012 - 06:57 PM
ChunLing, on 05 December 2012 - 06:41 PM, said:
But let's do it as a parallel friendly function.
local function intrusionTest()
local prohibit = {"computer","turtle","drive"}
while true do
os.pullEvent("peripheral")
for k,v in pairs(rs.getSides()) do
for i = 1,#peripheralType do
if peripheral.getType(v) == prohibit[i] then return v,prohibit[i] end
end
end
end
end
Now the function only ever ends if it finds a prohibited device, as long as it doesn't it just waits for a peripheral event and checks again. Note that this solves a problem I mentioned earlier, in that the local declaration of prohibit doesn't have to be repeated every time the detection loop runs, so there's that.Normally, if I were writing a program of this sort, I'd try to make an os.pullEvent loop the heart of the program. That would maximize the amount of control I'd have over everything. It also tends to mean that you have to write all your own input functions, though. So a bit of a hassle, if the function above will work.
My program is designed like every function call an other when it is abut to end. like so:
--gross representation function three(a, B)/> c = "stuff" print(a, b, c) end function two(a) b = "random stuff" three(a, B)/> end function one() a = "other stuff" two(a) end one()
#13
Posted 05 December 2012 - 09:49 PM
#14
Posted 06 December 2012 - 05:55 AM
ChunLing, on 05 December 2012 - 09:49 PM, said:
Ok, thanks for your help and patience.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











