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

Controlling Computer with chatroom?

Started by Rosze, 15 July 2014 - 06:31 PM
Rosze #1
Posted 15 July 2014 - 08:31 PM
I have a concept that I would like to try to make but I'm new to programming and ComputerCraft. I would like to control my base using a pocket computer connected to a chat room, but I can't figure how I could make other computers run a program trough this. Is there a way to "listen" on the chat room for a specific command and then executing a preset function when it hears it?
Arektor #2
Posted 15 July 2014 - 08:47 PM
You can use rednet to do it.

rednet.receive() to receive an order from your pocket computer, and rednet.send(computerID, message) to send message as an order to your computer.

Take a look at http://computercraft...iki/Rednet_(API)
It could help you for the syntax :)/>

For example :

local senderID, message = rednet.receive()
if message == "Order1" then
print("Executing the first order.")
elseif message == "Order2" then
print('Executing the second order.")
elseif message == "Order3" then
print("Executing the third order.")
end
for receiving and execute the order, and :

rednet.send(6,"Order1")
rednet.send(6,"Order2")
rednet.send(6,"Order3")
to send the order 1, 2 and 3 to the computer 6.

To get a computer's ID, type id.


To preset a function do :

function action1()
print("This is the action 1.")
end
action1()  -- Will execut what is in the action1() function, here it will print "This is the action 1."


Edit: Don't forget to type rednet.open("back") at the start of the program for your pocket computer and rednet.open(side) for your computer, where side is the side where is located the modem.
Edited on 15 July 2014 - 06:50 PM
Rosze #3
Posted 15 July 2014 - 09:26 PM
Is there a way to do it using the chat though? Rednet works too, but I'm curious if you can do something similar in the chatroom?
Cranium #4
Posted 15 July 2014 - 09:34 PM
are you talking about ingame chat? If so, try MoarPeripherals, it has a chatbox that sends events when people in range are chatting.
Rosze #5
Posted 15 July 2014 - 09:40 PM
Theres the program chat: chat host <hostname> chat join <hostname> <nickname>. I would like to maybe create one computer that host a chatroom and connect every computer to that chat room. Then using a pocket computer to control those computer via that chat room. Thought it could be fun way to control them.
hilburn #6
Posted 16 July 2014 - 12:11 AM
Unless you recoded the chatroom functions to listen out for certain commands then no it is not possible