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

Computronics Chat Box Door Opener

Started by WolfyXK, 23 December 2015 - 01:20 AM
WolfyXK #1
Posted 23 December 2015 - 02:20 AM
Just a little program to open a door when you say a selected message in chat, thanks again. - WolfyXK
also this is my first program I have posted on the forums so any advice/improvements would be much appreciated :)/>

Just place the chatbox anywhere touching the computer

pastebin get nsqR30yt startup


-- Change this code
local yourname = "WolfyXK"
local openmessage = "open" -- Make this lowercase
local doorside = "right"
local opentime = 4
-- 

while true do

local chat = { os.pullEvent("chat_message") }

if chat[3] == yourname and string.lower(chat[4]) == openmessage then
print("Door Opening")
rs.setOutput(doorside, true)
sleep(opentime)
term.clear()
rs.setOutput(doorside, false)
else
end
end




Edited on 24 December 2015 - 02:57 AM
Bomb Bloke #2
Posted 23 December 2015 - 05:22 AM
I wasn't sure how to get the code to restart other than to reboot so any advice would be much appreciated, thanks.

The idea is to wrap the relevant bit of code within a loop structure, for eg:

while true do  -- Loop repeats while condition is true; "true" is always true, so this one goes indefinitely.
  -- Code to repeat here.
end

I recommend a read of this guide.
WolfyXK #3
Posted 23 December 2015 - 11:26 AM
That should have been really obvious to me, I was just having some trouble with the event in the earlier stages and had to take the loop out, honestly don't know how I missed that :'D Thanks.
Selim #4
Posted 23 December 2015 - 04:13 PM
There is plenty of information out there on Computronics, both a wiki and the source code.
Wiki: http://wiki.vex.tty.sh/wiki:computronics
Source: https://github.com/asiekierka/Computronics
WolfyXK #5
Posted 23 December 2015 - 04:45 PM
Its just for anyone who is new to Lua and wants to use the chat box, as the wiki doesn't tell you exactly how to use the code.
Selim #6
Posted 23 December 2015 - 09:00 PM
It isn't a huge deal, but it does:
Computronics Wiki said:
  • say(message) - says a message within the chatbox distance.
  • (0.3.0+) getDistance() - gets the current listening/speaking distance.
  • (0.3.0+) setDistance() - sets the current listening/speaking distance. The maximum is defined in the config.
  • An event is sent every time the Chat Box receives a message. The name of the event is “chat_message”, the first parameter is the username and the second parameter is the message.

LDDestroier #7
Posted 04 January 2016 - 02:07 AM
local openmessage = "mellon"

I hope you get the reference
Edited on 04 January 2016 - 01:08 AM