r/ComputerCraft • • Aug 10 '21

Little problem

Using cc:tweaked and advanced peripherals. Advanced peripherals comes with the chat block, and I'm trying to pull a name from the chat event as a if statement. The end goal is to be able to have something automate every time a specific person talks. Trying to get the if statement to wait for the username "StartDebuffing" to be in chat, and then execute code. Any help is appreciated!

1 Upvotes

5 comments sorted by

3

u/fatboychummy Aug 11 '21

According to the AP docs page for the Chat Box, the following should work:

while true do
  -- get all data from the event
  local event, username, message, uuid = os.pullEvent("chat")

  -- Just a debug print
  -- Not actually needed, but nice for debugging things.
  print(string.format("%s (uuid: %s) said '%s'", username, uuid, message)

  -- Check if username matches what we want
  if username == "SomethingOrOther" then
    doSomething()
  end
end

1

u/Big_Ticket_7651 Aug 11 '21

Thanks! I'll test it out tonight.

1

u/Big_Ticket_7651 Aug 11 '21

Sadly doesn't work

2

u/fatboychummy Aug 11 '21

Please define "doesn't work".

Error? No output? Prints the debug message but doesn't do the if statement properly?