Jump to content




[lua][question] how to use one computer to trigger another one to runa program.


4 replies to this topic

#1 jamesscape2

  • New Members
  • 14 posts

Posted 26 April 2012 - 11:23 AM

Hi, this is my first post on this plus am a noob at lua.

EDIT: change the code in the first spoiler to the correct code that now correctly and properly works

this is my code for the computer to send the signal out to the other computer after the user has logged in. Feel free on this one to all so optimism some of the code for me it would be useful to me

Spoiler

and this is the code i have so far to start the program on the other computer.
at the moment i am just mucking around with it trying to see if it works, the program is in now way finished

Spoiler

thanks i have been try at this for a hour or so now so it would be great if i could get a straight answer how to fix it

THANKS

Edited by jamesscape2, 26 April 2012 - 02:18 PM.


#2 jamesscape2

  • New Members
  • 14 posts

Posted 26 April 2012 - 02:19 PM

Fixing or atleast telling my what to use to enable the other computer to detect the signal coming from the other computer to start its program would help me heaps

#3 libraryaddict

  • New Members
  • 195 posts

Posted 26 April 2012 - 02:32 PM

I dont like bundled cables and use a API to handle them. Which means i dont know how it works.
But for the second piece of code. You need "==" not "="
"==" compares one to another. "=" is setting one to another.

Controlling Computer
rednet.open("top") -- Opens a modem on top of the computer
User = {} -- Makes a table
ID = 0 --Set this to the computerID of the one you are controlling

--For the User and Password. You can add multiple users and a password per user.
--For just one user. Delete User[2]. To add a user use User[3] User[4] etc.
--You need to do the same thing for Password. But with a password.
--You proberly dont want to use capitalized letters. Its caps specific. As in you need to type the caps in correctly too.
User[1] = "Jack"
User[2] = "Sam"
Password = {}
Password[1] = "Jill"
Password[2] = "Dam"
function Clear()
  term.clear()
  term.setCursorPos(1,1)
end
function OpenDoor(UserName)
  Clear()
  print("Welcome "..UserName)
  rednet.send(ID, "Open")
  sleep(5)
  rednet.send(ID, "Close")
end

while true do -- While true is true do this
  Clear() -- Calls on function Clear() which clears the screen
  write("User: ")
  local Ignore,UserTry = pcall(read, "*") -- pcall catches errors and throws it as a status
  write("Password: ")
  local Ignore,PassTry = pcall(read, "*")
  for n=1,#User do -- Starting from 1 to the max Users there is. Look for this user.
	if User[n] == UserTry and PassTry == Password[n] then -- If the user exists and the pass is correct. Do it!
	  OpenDoor(User[n])
	  break -- Exit the loop, We dont want any duplicate user errors, And this loop no longer needs to run
	end
  end
end

And the slave computer
rednet.open("top")
ID = 0 --Set this to the master Computer
term.setCursorPos(1,1)
term.clear()
print("Dobby says you may NOT touch this computer!")
while true do
  event,param1,param2 = os.pullEventRaw() -- os.pullEvent() is a modified version of os.pullEventRaw() in that its safer to use. But its not Ctrl+T proof
  if event == "rednet_message" and param1 == ID then
	if param2 == "Open" then
	  rs.setOutput("back", true)
	elseif param2 == "Close" then
	  rs.setOutput("back", false)
	end
  end
end

I didnt put bundled in :
This is also Ctrl+T proof.
Just setup the users/ID's and rename as startup.
Then restart the computers.
Viola!

If you dont want it Ctrl+T proof then rename os.PullEventRaw() to os.pullEvent() and pcall(read, "*") to read()

So anyways.
You should be able to use/look at that

#4 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 26 April 2012 - 02:33 PM

coudnt u just ask for any redstone input ? like

send:
redstone.setOutput("back", true)
sleep(sleepTime3)
redstone.setOutput("back", false)

receive:
while true do 
if rs.getInput("back") == true then
break
end
end
print("working")

also ur using while wrong :)/> thats the main problem
i fixed it 4 u

#5 libraryaddict

  • New Members
  • 195 posts

Posted 26 April 2012 - 02:39 PM

I could of sworn he asked to control a computer from another computer.

Was wondering if I should give him code to transfer entire files from computer to computer.

Oh well. My mistake xD





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users