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

use rednet to unlock a computer

Started by willwalker1313, 21 November 2012 - 04:08 PM
willwalker1313 #1
Posted 21 November 2012 - 05:08 PM
i am not sure how to do this. i have 4 computers with modems and i want the 4 computers to unlock the main computer using wireless modems and discs. I dont expect someone to do this for me i just need to know where to start.
Goof #2
Posted 21 November 2012 - 10:07 PM
You can make a startup script on the computers.

Then make the computers recieve.. If the computer receives a "unlock" password, it will break the loop, and then you can use the computer.


an example:
Spoiler

os.pullEvent = os.pullEventRaw
local running = true
local unlockerId = "10" --the server id, or the id of the computer, which should be able to unlock the pc.
local unlockMSG = "unlockComputer"
local modemSide = "right"
rednet.open(modemSide)
while running do
term.clear()
id, msg = rednet.receive(5)
if id == unlockerId then -- delete this if you want all computers, to unlock this computer.
if msg == unlockMSG then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("this computer is unlocked...")
sleep(5)
term.clear()
term.setCursorPos(1,1)
running = false
end
end
end
willwalker1313 #3
Posted 22 November 2012 - 06:03 AM
i keep getting rednet :313: string expected

never mind i figure it out.

thanks for the help.
willwalker1313 #4
Posted 22 November 2012 - 02:09 PM
i edited your example code.
i am trying to get it to need 4 different passwords to unlock it but when i send the passwords it does nothing.
sorry i am a noob at this i am still trying learn LUA.

Spoileros.pullEventRaw()
local running = true
local unlockerId = ("8")
local unlockerId = ("7")
local unlockerId = ("6")
local unlockerId = ("5")
local unlockMSG = "12345"
local unlockMSG = "54321"
local unlockMSG = "123456"
local unlockMSG = "654321
local modemSide = ("back")
rednet.open("back")
while running do
term.clear()
id, msg = rednet.receive(5)
if msg == unlockMSG then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("this computer is unlocked…")
sleep(5)
term.clear()
term.setCursorPos(1,1)
running = false
end
end
Kingdaro #5
Posted 22 November 2012 - 04:00 PM
I believe your first line should be

os.pullEvent = os.pullEventRaw
instead.
willwalker1313 #6
Posted 22 November 2012 - 04:59 PM
doesn't do anything other then not showing CraftOS 1.4
Goof #7
Posted 22 November 2012 - 07:43 PM
You should make an table. Thats a bit easier, to read.. Like all your ids, and passwords.

like this

local idsToUnlock = { 10, 14 }
local passwords = { "unlockPc", "unloPc" }


Then you could do:


id, msg = rednet.receive()
for i, k in ipairs(idsToUnlock) do
if id == idsToUnlock[i] then
if msg == passwords[i] then 
print("unlocked")
end
end