【问题标题】:Attempting to connect to a websocket returns "Attempt to call nil" in computer craft尝试连接到 websocket 在计算机工艺中返回“尝试调用 nil”
【发布时间】:2021-04-27 04:55:26
【问题描述】:

我正在尝试连接到 twitch chat-irc websockets,但是当我运行我的代码进行测试时,它返回 .temp:7:尝试调用 nil。我听说它必须与函数有关,但我的代码没有函数,只有字符串,并且只有 2 行连接到第 7 行。有人知道如何解决这个问题吗?

local Channel = *my channel*
local Name = *Bot account name*
local Pass = *oauth code*

local cum = "wss://irc-ws.chat.twitch.tv:443"

local ws = http.websocket(cum)
if ws then
        print("Connection Established")

websocket.send("PASS " ..Pass .."\r\n")
websocket.send("NICK " ..Name .."\r\n")
websocket.send("Join " ..Channel .."\r\n")

【问题讨论】:

    标签: lua computercraft


    【解决方案1】:

    您创建了一个名为 ws 的变量,然后继续使用一个名为 websocket 的变量,但该变量并不存在。将最后 3 行替换为:

    ws.send("PASS " ..Pass .."\r\n")
    ws.send("NICK " ..Name .."\r\n")
    ws.send("Join " ..Channel .."\r\n")
    

    它与函数有关,因为send() 是一个函数。您试图在不存在的变量上调用 send(),导致该错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 2021-07-11
      • 2021-03-02
      • 1970-01-01
      • 2020-11-27
      • 2019-05-25
      • 2017-02-20
      相关资源
      最近更新 更多