34 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!
7083 posts
Location
Tasmania (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.
34 posts
Posted 20 December 2016 - 06:18 PM
THANKS!
34 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 on 20 December 2016 - 05:39 PM
172 posts
Location
USA
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