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

(MoarPeripherals) Chat Box help needed

Started by NegativeVoltage, 01 December 2015 - 10:57 PM
NegativeVoltage #1
Posted 01 December 2015 - 11:57 PM
I've done a bit of research and couldn't find much. Could someone explain how I use the chat box from moarperipherals? Just basic stuff, like what someone's saying, and how to make the chat box say things too.
Bomb Bloke #2
Posted 02 December 2015 - 12:32 AM
These days, the closest thing to "documentation" remaining would be the source of the blocks here.

In brief, though, when the Chat Box detects a player using chat, it'll generate an event which can be pulled like so:

local event, chatBoxSide, playerName, message = os.pullEvent("chat_message")

If a player starts their chat message with ##, then only chat boxes will "see" it (you get a "chatbox_command" event instead of a "chat_message" event). Certain other happenings - such as player deaths - also generate events; I like to use this basic loop to give me information about events I'm unfamiliar with:

while true do print(os.pullEvent()) end

Chat boxes can be made to speak by wrapping them and then calling their "say" function:

local myChatBox = peripheral.wrap(chatBoxSide)

myChatBox.say("Hello world")

If you want to use private messages, use "tell":

myChatBox.tell("NegativeVoltage", "Hello")

It's fairly simple, but I've also got this example script that I wrote for use with this API.

Keep peripheral.getMethods() in mind for finding more functions.

There are also "admin" chatboxes available only in the creative inventory. Regular ones are range-limited, subject to the MoarPeripherals config file; admin ones aren't, and if memory serves, they can even generate events letting you know when players join/leave the server.
Edited on 01 December 2015 - 11:38 PM