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

Made one computer control other computers programs

Started by PoroCoco, 21 July 2016 - 10:49 AM
PoroCoco #1
Posted 21 July 2016 - 12:49 PM
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 ^^)
RoD #2
Posted 21 July 2016 - 11: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
Lupus590 #3
Posted 22 July 2016 - 01:23 AM
http://www.computercraft.info/forums2/index.php?/topic/17229-vncd-an-nsh-compatible-vnc-server/
http://www.computercraft.info/forums2/index.php?/topic/6472-nsh-now-with-previous-session-resume/

can these do anything for you?
Emma #4
Posted 22 July 2016 - 01:35 AM

A little overkill for something like this ;p
PoroCoco #5
Posted 22 July 2016 - 02:11 PM
I'll try it thanks guys !
PoroCoco #6
Posted 22 July 2016 - 06:57 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
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 !
The Crazy Phoenix #7
Posted 23 July 2016 - 11: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?
PoroCoco #8
Posted 24 July 2016 - 07:03 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?
The computers are 5 blocks from each others
RoD #9
Posted 30 July 2016 - 10:28 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?

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 on 30 July 2016 - 08:29 PM