首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ComputerCraft抽搐跟随程序不起作用

ComputerCraft抽搐跟随程序不起作用
EN

Stack Overflow用户
提问于 2015-03-20 05:57:43
回答 2查看 484关注 0票数 0

我有一个关于计算机技术的程序,名为Twitch,它显示了我在Twitch上有多少素食主义者和追随者。当我尝试运行它时,它会给出以下错误:

抽搐:39:尝试索引 ?(一个nul值)

守则是:

代码语言:javascript
运行
复制
    -- Written By Bacon_Donut
-- http://twitch.tv/bacon_donut
-- API call updated by @darkgoldblade on twitter

-- View all my public pastebin codes at:
-- http://pastebin.com/u/bacon_donut

-- This is formatted to fit on a 1x3 wall of Advanced Monitors
-- with an Advanced Computer on the left side.
-- To get this to work you need to edit the streamid variable then run these four commands:

-- label set SomeKindOfNameHere
-- pastebin get 4nRg9CHU json
-- pastebin get vhn1z23v startup
-- startup

-- ChangeLog:
-- Feb 16, 2015 - @CoolAcid
-- Added automatic download of JSON parser
-- Fixed the offline streamer detection
-- Added last follower option

-- Twitch Name of the Streamer
streamid = "Bacon_Donut"


-- SleepTime is how often to grab new data. Set here to one minute.
-- Set it too fast and twitch will flag you for spam
-- and stop giving you data
SleepTime = 60

if not fs.exists('json') then
        write("JSON API not found - Downloading")
        shell.run("pastebin get 4nRg9CHU json")
end

os.loadAPI("json")
local m = peripheral.wrap("right")
m.setCursorPos(1,1)

function getFollowers()

        str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll()
        obj = json.decode(str)
        follows = json.encodePretty(obj._total)

        m.setCursorPos(1,3)    
        m.write("Twitch Followers: ")
        m.write(follows)

        return follows
end

function getFollower()

        str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll()
        obj = json.decode(str)
        follower = json.encodePretty(obj.follows[1].user.name)

        m.setCursorPos(1,5)    
        m.write("Follower: ")
        m.write(follower)

        return follows
end

function getViewerCount()
        lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamid).readAll()
        lobj = json.decode(lstr)
        m.setCursorPos(1,1)


        if lobj.stream == nil then
                m.write(streamid)
                m.setCursorPos(1,4)
                m.write("Live Viewers: Offline")
        else
                live = json.encodePretty(lobj.stream.viewers)
                m.setBackgroundColor(colors.yellow)
                m.clear()
                m.write(streamid)
                m.setCursorPos(1,4)
                m.write("Live Viewers: ")
                m.write(live)          
        end

        return live
end

while true do
        m.setCursorPos(1,1)
        m.setBackgroundColor(colors.white)
        m.setTextColor(colors.blue)
        m.setTextScale(1)
        m.clear()

        m.write(streamid)
        m.setCursorPos(1,4)

        local status, live = pcall(function () getViewerCount() end)

        if status then
                -- do nothing
        else
                m.write("Live Viewers: Loading...")
        end

        local status, followsCount = pcall(function () getFollowers() end)

        m.setCursorPos(1,3)    

        if status then         
                -- do nothing
        else           
                m.write("Twitch Follows: Loading...")
        end

        m.setCursorPos(1,5)    

        local status, live = pcall(function () getFollower() end)

        if status then
                -- do nothing
        else
                m.write("Follower: Loading...")
        end



        sleep(SleepTime)
end
EN

回答 2

Stack Overflow用户

发布于 2015-04-08 18:26:49

李仪的假设是错误的。

考虑到您的错误是明确的,尝试索引吗?(一个零值),那就意味着m是零。换句话说,您需要将一个外围设备(在本例中是我假设的监视器)放在计算机的右侧。

根据守则:

代码语言:javascript
运行
复制
-- This is formatted to fit on a 1x3 wall of Advanced Monitors
-- with an Advanced Computer on the left side.

所以你需要监视器在右边。

也许您应该阅读其他人的代码中提供的说明,而不是想知道它为什么不能工作。

票数 2
EN

Stack Overflow用户

发布于 2015-03-23 10:50:27

你包装的外围设备实际上不具备setCursorPos()的能力

Sidenote:

多行注释通常如下所示:

代码语言:javascript
运行
复制
--[[
Stuff here is a comment
]]--
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29160300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档