Jump to content




Made one computer control other computers programs

lua networking wireless

  • You cannot reply to this topic
8 replies to this topic

#1 PoroCoco

  • Members
  • 4 posts

Posted 21 July 2016 - 11:49 AM

Hello everyone,
I started learning ComputerCraft 2 days ago and I wanted to do a shooting range.
I have 13 targets with 1 computer behind every targets with this program:

redstone.setOutput("back",true)
while true do
sleep(0.1)
if redstone.getInput("left",true) then
redstone.setOutput("back",false)
return
end
end

So when the program is launched the target get up and when the target is hit it stop the program.
But I want that 1 computer randomly chose 1 of the 13 computer, launch the program, wait until the programs is close(when a target is hit) and chose another random computer ect... until 10 targets are been hitten then show how much time we took to take down the 10 target and close himself.
This has been 2 days and I can't figure how to do it so if someone could help me :)
I'm playing on the Ftb infinity Evolved modpack on a private server.
(I apologize for all of my grammar mistakes because english isn't my native language ^^)

#2 RoD

  • Members
  • 313 posts

Posted 21 July 2016 - 10:56 PM

You want to interact with other computers? You might want to use rednet. The api is really easy to understand. Give it a try

#3 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 22 July 2016 - 12:23 AM

http://www.computerc...ble-vnc-server/
http://www.computerc...session-resume/

can these do anything for you?

#4 Emma

  • Members
  • 216 posts
  • Locationtmpim

Posted 22 July 2016 - 12:35 AM

View PostLupus590, on 22 July 2016 - 12:23 AM, said:


A little overkill for something like this ;p

#5 PoroCoco

  • Members
  • 4 posts

Posted 22 July 2016 - 01:11 PM

I'll try it thanks guys !

#6 PoroCoco

  • Members
  • 4 posts

Posted 22 July 2016 - 05:57 PM

View PostRoD, on 21 July 2016 - 10:56 PM, said:

You want to interact with other computers? You might want to use rednet. The api is really easy to understand. Give it a try
So i don't know what i'm doing wrong.
PC-1
local modem = peripheral.wrap("right")
modem.open(4)
rednet.open("right")
rednet.send(5,"ok")
PC-2
local modem = peripheral.wrap("right")
modem.open(5)
rednet.open("right")
local senderId, message, protocol = rednet.receive()
print(message)
I start PC-2 first then PC-1 but PC-2 never receive the message...
Can someone help me?
Thanks in advance !

#7 The Crazy Phoenix

  • Members
  • 136 posts
  • LocationProbably within 2 metres of my laptop.

Posted 23 July 2016 - 10:01 PM

Rednet automatically handles the modem API for you, don't bother wrapping (or opening) the modem in either program. Are you sure the computers are not out of range?

#8 PoroCoco

  • Members
  • 4 posts

Posted 24 July 2016 - 06:03 PM

View PostThe Crazy Phoenix, on 23 July 2016 - 10:01 PM, said:

Rednet automatically handles the modem API for you, don't bother wrapping (or opening) the modem in either program. Are you sure the computers are not out of range?
The computers are 5 blocks from each others

#9 RoD

  • Members
  • 313 posts

Posted 30 July 2016 - 09:28 PM

View PostThe Crazy Phoenix, on 23 July 2016 - 10:01 PM, said:

Rednet automatically handles the modem API for you, don't bother wrapping (or opening) the modem in either program. Are you sure the computers are not out of range?

alright let me give you a starting point:

Computer 1, sender (in this case, with a WIRELESS modem on his back):
rednet.open("back")
rednet.send(5, "ok") -- 5 is the id, as i am sure you already know

Computer 2, receiver (in this case, with a WIRELESS modem on his back):
rednet.open("back")
while true do -- this will run over everytime you get a new message
	senderId, mess = rednet.receive()
	print(mess)
end

If you use this code it will work. 100%,
However, if you are already trying to use the rednet on your existing code there must me some tweaks you need to make (maybe not).
Note: also after running the receiver program on the receiver computer, check if the wireless modem turns red on the side.

Edit: quoted the wrong person xD Sorry, Phoenix.

Edited by RoD, 30 July 2016 - 09:29 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users