Jump to content




[MoarPeripherals] Chatbox Help!

peripheral computer help

4 replies to this topic

#1 DejaVu

  • Members
  • 31 posts

Posted 19 December 2016 - 04:53 PM

So, I'm noobish at Lua, and I want to make a chatbot using moarperipherals chatbox, I want it so anyone can talk to it (for example, "hi" would make the chatbox say "Hello!")
Thanks!

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 December 2016 - 11:49 PM

The documentation can be found here. A basic script such as you describe might go like:

local chatbox = peripheral.find("chatbox")

chatbox.setLabel("myChatbox")

while true do
	local event, side, playerName, message = os.pullEvent("chat_message")
	
	print(playerName .. " said: " .. message)
	
	chatbox.tell(playerName, "Hello!")
end

... though you may wish to make use of the String library to help you parse incoming messages and figure out if they were "aimed" at the chatbox or not.

#3 DejaVu

  • Members
  • 31 posts

Posted 20 December 2016 - 06:18 PM

THANKS!

#4 DejaVu

  • Members
  • 31 posts

Posted 20 December 2016 - 06:37 PM

one more thing: i get "chat:2: attemp to index ? (a nil value)" when i do chatbox.setLabel,
never mind fixed

Edited by DejaVu, 20 December 2016 - 06:39 PM.


#5 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 21 December 2016 - 12:05 AM

Chatbox's are pretty simple. Here is an example script

local chatbox = peripheral.find("chatbox")
while true do
    local event, side, player, message = os.pullEvent("chat_message")
    if message == "hello" then
      chatbox.say("Hello "..player.."!")
    end
end

Here is a simple script demonstrating the chatbox's abilities
The script detects if a user's message is longer then 20 chars.

local chatbox = peripheral.find("chatbox")
while true do
    local event, side, player, message = os.pullEvent("chat_message")
    if #message > 20 then
      chatbox.tell(player, "Please stop with the long messages!")
    end
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users