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

Peripheral++ chatbox

Started by Enderslime, 17 November 2015 - 07:42 PM
Enderslime #1
Posted 17 November 2015 - 08:42 PM
I've gotten used to using chat boxes to say messages, but im having 2 problems.

My first problem is the name, it shows the coordinates of the chat box, and i have no idea how to rename it.

my second problem, is receiving, so if i wrote Slap "Player" it would read slap and put player as a variable.

i wont be able to reply for 30 minutes.
valithor #2
Posted 17 November 2015 - 09:24 PM
The coordinates is something that enabled in the config iirc. So you would need to change that option in the config for it to not show them.

I have not used peripherals ++ in a while, but I am assuming you know how to get what a player said, so:

str = "slap eskreme"
player = str:match("slap (%S+)")

So what that is doing exactly, is it checks to see if the phrase "slap " is in the string, and then returns everything between it and the next space, so in this case "eskreme".
Edited on 17 November 2015 - 08:24 PM
Enderslime #3
Posted 17 November 2015 - 09:44 PM
c = peripheral.wrap("top")

while true do
event, player, message = os.pullEvent("chat")
if message == "AIReboot" then
os.reboot()
elseif message == "Hello ChatAI" then
c.say("Hello, "..player)
elseif message == "!slap" then <———————————————–| << hardcode slap code, how would i intergrate that in?
c.say("ChatAI Smashes Creep's Skull In With A Cast Iron Skillet!")<<|
end
end
Twijn #4
Posted 18 November 2015 - 10:34 PM
c = peripheral.wrap("top")

while true do
event, player, message = os.pullEvent("chat")
if message == "AIReboot" then
os.reboot()
elseif message == "Hello ChatAI" then
c.say("Hello, "..player)
elseif message == "!slap" then <———————————————–| << hardcode slap code, how would i intergrate that in?
c.say("ChatAI Smashes Creep's Skull In With A Cast Iron Skillet!")<<|
end
end

If you'd prefer to keep it as !slap, you could change the "if" statement to this:

elseif message:sub(1,5) == "!slap" then
This would only get the part of the string that is from the first character(the '!') to the fifth character (the 'p'), then it will compare it.
Then you would simply change the code that valithor suggested like this:

player = str:match("!slap (%S+)")
which would ignore the '!slap ' part and only get the argument that is after that which should be the name.
Edited on 18 November 2015 - 09:34 PM