ComputerCraft Twitch Follower Program Not Working - minecraft

I have a program on Computercraft named Twitch that shows how many veiwers and followers I have on Twitch. When I try to run it it gives me this error:
twitch:39: attempt to index
? (a nul value)
The code is:
-- 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

Lee Yi is incorrect in his assumption.
Considering that your error is specifically, Attempt to index ? (a nil value), then that means that m is nil. In other words, you need to put a peripheral, (In this case I'm assuming a monitor) to the right of the computer.
From the code:
-- This is formatted to fit on a 1x3 wall of Advanced Monitors
-- with an Advanced Computer on the left side.
So you need the monitors, ON THE RIGHT.
Perhaps you should read the instructions provided with someone else's code rather than wondering why it isn't working.

The peripheral you wrapped doesn't actually have the ability to setCursorPos()
Sidenote:
Multi line comments are usually done like this:
--[[
Stuff here is a comment
]]--

Related

use associate array total value count Lua

i want to count the data type of each redis key, I write following code, but run error, how to fix it?
local detail = {}
detail.hash = 0
detail.set = 0
detail.string = 0
local match = redis.call('KEYS','*')
for i,v in ipairs(match) do
local val = redis.call('TYPE',v)
detail.val = detail.val + 1
end
return detail
(error) ERR Error running script (call to f_29ae9e57b4b82e2ae1d5020e418f04fcc98ebef4): #user_script:10: user_script:10: attempt to perform arithmetic on field 'val' (a nil value)
The error tells you that detail.val is nil. That means that there is no table value for key "val". Hence you are not allowed to do any arithmetic operations on it.
Problem a)
detail.val is syntactic sugar for detail["val"]. So if you expect val to be a string the correct way to use it as a table key is detail[val].
Possible problem b)
Doing a quick research I found that this redis call might return a table, not a string. So if detail[val] doesn't work check val's type.

BAPI_ALM_ORDER_MAINTAIN Error IW:430 - Start date may not fall after end date

I'm calling the BAPI_ALM_ORDER_MAINTAIN function module like so to create a work order:
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = lt_methods
it_header = lt_header
it_header_up = lt_header_up
it_operation = lt_operation
it_operation_up = lt_operation_up
it_srule = lt_srule
it_srule_up = lt_srule_up
return = lt_return
extension_in = lt_extension_in.
In my lt_header table, I have the following information:
It's proven problematic for me to leave the finish_date initial. When I make the function module call, the error 430 from the IW message class is returned: Start date may not fall after end date. If I enter a valid finish date, the work order is created successfully.
I'm able to create a work order manually in IW31 without entering a finish_date.
Here is the configuration for this particular plant and order type (which I've removed from the photo):
Is there a way to submit this BAPI without specifying a finish date?
Ensure that you flag the start date with X in it_header_up, but leave the finish date unflagged - this way the missing finish date should not cause issues.

Corona Lua SQLite

this is my first question on stackOverflow.
I'm working with Corona and I'm having an issue accessing a SQLdb (I'm a bit of a SQL noob.)
I'm trying to access and return a value I've stored in the database.
Here's some code samples:
print("---------------- How I Create New Player Save Data")
local entry = [[CREATE TABLE IF NOT EXISTS playerData (key STRING PRIMARY KEY, content INTEGER);]]
db:exec(entry)
entry = [[INSERT INTO playerData VALUES ("LastLoginTime", 0);]]
db:exec( entry )
entry = [[INSERT INTO playerData VALUES ("Credits", 1000);]]
db:exec( entry )
entry = [[INSERT INTO playerData VALUES ("Level", 1);]]
db:exec( entry )
Now this function works, it will print everything in the db (i pass in 'dbName'):
--print all the table contents
for row in db:nrows("SELECT * FROM "..dbName) do
local text = row.key..": "..row.content
end
This doesn't work, it returns '0':
local grabCredits = "SELECT content FROM playerData WHERE key='Credits'"
local credits = db:exec(grabCredits)
print("-- value: "..credits)
Neither does this, also returns '0':
local grabCredits = "SELECT key FROM playerData WHERE content>=10"
local credits = db:exec(grabCredits)
print("-- value: "..credits)
I don't understand what I'm doing wrong. Maybe I need to use another function call on the db other than exec(). I realize I could iterate through the db every time I want to access a single entry, but that just seems inefficient.
Any help is very much appreciated.
If you want results, you must use some form of iterator. SQLite always returns rows for a query result.
This is similar to what I'm using to retrieve one result from my database and works well for me.
local query = "SELECT content FROM playerData WHERE key = 'Credits' LIMIT 1"
local queryResultTable = {}
local queryFunction = function(userData, numberOfColumns, columnValues, columnTitles)
for i = 1, numberOfColumns do
queryResultTable[columnTitles[i]] = columnValues[i]
end
end
db:exec(query, queryFunction)
for k,v in pairs(queryResultTable) do
print(k,v)
end

My simple sql update query is not working right :(

I've got a simple sql query that is trying to update a single row. The code came from some Linq-to-sql code (i used Profiler to grab it), but please don't worry about the source (L2S) ... that's irrelivant to the question.
Now, when i try and do an update with the where clause, I get 0 rows updated.
I then try and do a select with the same where clause. i get a single result back. Ok, so the data is there.
It's only when i turn off some of the where clause statements does the query finally work. I just don't get it :(
I can't really explain it. So I made a video showing this.
Please watch the video on YouTube here.
Can anyone help? It's really weird :(
Database is MS-SQL 2008.
-- UPDATE
The sql i'm trying to execute (after i've cleaned it up from L2S)..
update tblBoardPost
set IsSticky = 1
where IdBoardPost = 1278
and IdAddress = 212787
and Subject = N'ttreterte'
and Banner is null
and UniqueSubject = N'ttreterte5'
AND (NOT ([IsAnnouncement] = 1))
AND (NOT ([IsSticky] = 1))
AND (NOT ([IsLocked] = 1))
and IsVisible = 1
and IdUserModified = 1
AND [IdNewsArticle] IS NULL
AND [IdList] IS NULL
(note: yes, i know the NOT (blah = 1)) is weird, but that's L2S that made that.
Update 2:
The code in the video is being ran in a transaction/rollback trans. this means that if i do run one of those weird scenario's that works, the change works .. but the rollback undoes it .. so when i run it a 2nd time .. the original value has been returned to the db row.
Also, in the vid, the select query is not exactly the same as the update query .. because i've been trying so many permutations (with no luck) .. so by the time i made the vid .. i forgot to show the original code. That said, the same code in both the select statement and the update/where statement (when i copy/paste on my machine) reproduces the exact same probs :(
Update 2 :)
As per Lieven's request, here's the screenshot showing the code and then the results.
alt text http://img196.imageshack.us/img196/7111/lieven.png
I checked your video, and you should try the same SQL conditions, that you used to return one row in your select query, in your update query. The conditions in the two SQL statements in your video aren't the same, and I don't really care why; they're not apples to apples.
Just copy and paste the working WHERE clause over the non-working one.
In the video, your select goes like
and not IsAnnouncement = 1
wich gives entirely different results as in your update
and not (IsAnnouncement = 1)
It seems you are suffering from an operator precedence issue .
Edit
as the queries don't match in your video and although you say they have matched could you copy paste following script and let us know if or if they do not give you the same results? (I for one would have a hard time believing that the rows affected would differ)
begin tran
select *
from tblBoardPost
where
IdBoardPost = 1278
and IdAddress = 212787
and Subject = N'ttreterte'
and Banner is null
and UniqueSubject = N'ttreterte5'
AND (NOT ([IsAnnouncement] = 1))
AND (NOT ([IsSticky] = 1))
AND (NOT ([IsLocked] = 1))
and IsVisible = 1
and IdUserModified = 1
AND [IdNewsArticle] IS NULL
AND [IdList] IS NULL
update tblBoardPost
set IsSticky = 1
where
IdBoardPost = 1278
and IdAddress = 212787
and Subject = N'ttreterte'
and Banner is null
and UniqueSubject = N'ttreterte5'
AND (NOT ([IsAnnouncement] = 1))
AND (NOT ([IsSticky] = 1))
AND (NOT ([IsLocked] = 1))
and IsVisible = 1
and IdUserModified = 1
AND [IdNewsArticle] IS NULL
AND [IdList] IS NULL
rollback tran

VCL SQL [Query parameters error]

C++Builder ADOQuery SQLServer
Continue of This questions line
using this select with procedure :
SELECT
C.Hint,
CAST(CASE WHEN T2.ID_Param IS NULL THEN 1 ELSE 0 END as bit) AS Visi
FROM
CfgListParIzm C
LEFT JOIN
(
SELECT
T.ID_Param
FROM
TbUserParam T
WHERE
T.ID_User = #ID_User
) T2 On T2.ID_Param = C.ID_ListParIzm
WHERE
C.ID_ListGroupParIzm = #ID_ListGroupParIzm
Code :
AQ4->Close();
AQ4->Parameters->Items[1]->Value=(int)TS->Tabs->Objects[NewTab];
AQ4->Open();
Error :
List index of bounds (1)
But I can see this error only on run program.
Test query->grid activation works normal (with manually setup properties)
also if I do
AQ4->Close();
// AQ4->Parameters->Items[1]->Value=(int)TS->Tabs->Objects[NewTab];
AQ4->Open();
error :
AQ4: Field 'Visi' not found
AQ4 SQL :
FlowClientHardQ :ID_User, :ID_ListGroupParIzm
I also tough about DBGrid&Checkbox compability (Source) but as my field is normal bit I think that's not trouble, I made a mistake somewhere else...
Not sure about C++ builder, but in Delphi VCL, input parameters shall be marked with : and not with #.
First, put the query at design time in a query component and inspect the parameters property. If there's no parameters defined, try changing the # for :
Now, you are making more than one question here... so, let's go step by step.