【发布时间】:2018-05-31 19:18:29
【问题描述】:
我一直在尝试使用 Love2D 连接到 Twitch 聊天 IRC。它设法连接(if connect == 1 then)。我只是不确定如何接收发送给我的任何 IRC 消息 (love.update())。
function love.load()
oauth = "oauth:someoauthhere"
user = "botname"
channel = "channeltojoin"
love.graphics.setFont(love.graphics.newFont(32))
socket = require("socket")
irc = socket.tcp()
connect = irc:connect("irc.chat.twitch.tv", 6667)
if connect == 1 then -- MAKES IT PAST THIS
irc_messages = {}
irc:send("PASS " .. oauth)
irc:send("USER " .. user)
irc:send("JOIN #" .. channel)
end
end
function update(dt)
line, err = irc:receive() --> Returns nothing
if line then
table.insert(irc_messages, line)
end
end
function love.draw()
if not next(irc_messages) == nil then
love.graphics.printf(table.concat(irc_messages, "\n"), 0, 0)
end
end
【问题讨论】:
-
irc:receive() 返回什么?
-
没什么。我一个都没收到。变量“line”和“err”只是 nil。
-
它至少应该给出一个错误信息。您是否尝试提供文档中列出的任何模式? w3.impa.br/~diego/software/luasocket/tcp.html#receive
-
"*a"和"*l"方法我都试过了。 -
irc:connect() 在遇到错误时返回nil and an error message as the second argument。为这个错误提供第二个变量,看看它是什么。