15 posts
Location
united kingdom
Posted 30 March 2014 - 09:16 AM
Hello i get this error when using open peripherals docs program
docs :45: attempt to index ? (a number value)i'm using minecraft 1.6.4
computercraft version 1.58
OpenPeripheral-0.2.1-forge9.11.0.883-snapshot-68
Any help is greatly appreciated this code was Made by SinZ and boq
Link to original code
https://github.com/OpenMods/OpenPeripheral/blob/master/lua/openperipheral/lua/docsSpoiler
local args = {...}
if #args == 0 then
print("usage: docs <side> (function)")
return
end
local side = args[1]
local p = peripheral.wrap(side)
if not p then
print("No peripheral on '" .. side .. "'")
return
end
if not p.getAdvancedMethodsData then
print("Peripheral '" .. peripheral.getType(side) .. "' is not OpenPeripheral(TM)")
return
end
local info = p.getAdvancedMethodsData()
function argName(arg)
if arg.vararg then
return arg.name.."..."
elseif arg.optional then
return arg.name.."?"
else
return arg.name
end
end
if #args == 1 then
for name,data in pairs(info) do
args = {}
for _,arg in pairs(data.args) do
table.insert(args, argName(arg))
end
print(name.."("..table.concat(args,",")..")")
end
else --must be 2 or more
for name,data in pairs(info) do
if args[2]:lower() == name:lower() then
print(name..": "..data.description)
print("returns: "..string.lower(table.concat(data.returnTypes,',')))
if #data.args > 0 then -----------------------------------------------------------------------This is the line the error is on
print("args: ")
for _,arg in ipairs(data.args) do
print(" - ("..arg.type:lower()..")"..argName(arg)..": "..arg.description)
end
end
end
end
end
7508 posts
Location
Australia
Posted 30 March 2014 - 09:20 AM
Could you please tell me what peripheral this is on?
if #data.args > 0 then -----------------------------------------------------------------------This is the line the error is on
its actually on this one
if args[2]:lower() == name:lower() then
Edited on 30 March 2014 - 07:23 AM
15 posts
Location
united kingdom
Posted 30 March 2014 - 02:39 PM
no as far as i'm aware it should work on any and then list all available methods for it at least thats what github and the thread says
7508 posts
Location
Australia
Posted 30 March 2014 - 11:32 PM
Yes but the point is I was trying to figure out why it was going wrong with the certain peripheral and then I was going to fix it on GitHub if needed so future versions have the fix.
However here is a 'dirty' fix. change this lin
if args[2]:lower() == name:lower() then
to this
if args[2]:lower() == tostring(name):lower() then
Edited on 30 March 2014 - 09:33 PM
15 posts
Location
united kingdom
Posted 31 March 2014 - 08:15 AM
ok sorry i understand what you meant it wasn't working with any peripheral
7508 posts
Location
Australia
Posted 31 March 2014 - 09:26 AM
you didn't have a peripheral and it got to that line? o.O what were you running the program with?
7083 posts
Location
Tasmania (AU)
Posted 31 March 2014 - 10:36 AM
I think he's saying it errored out no matter what peripheral he connected to it, which would make me suspect that the OpenPeripheral version number he listed earlier is going to be relevant.
15 posts
Location
united kingdom
Posted 31 March 2014 - 08:01 PM
yes thats right bomb bloke no matter what peripheral i used it still errored out
Update: the "dirty Trick" you provided works however i now get this error on line 44
docs:44: bad argument: tabel expected, got nil
Spoiler
local args = {...}
if #args == 0 then
print("usage: docs <side> (function)")
return
end
local side = args[1]
local p = peripheral.wrap(side)
if not p then
print("No peripheral on '" .. side .. "'")
return
end
if not p.getAdvancedMethodsData then
print("Peripheral '" .. peripheral.getType(side) .. "' is not OpenPeripheral(TM)")
return
end
local info = p.getAdvancedMethodsData()
function argName(arg)
if arg.vararg then
return arg.name.."..."
elseif arg.optional then
return arg.name.."?"
else
return arg.name
end
end
if #args == 1 then
for name,data in pairs(info) do
args = {}
for _,arg in pairs(data.args) do
table.insert(args, argName(arg))
end
print(name.."("..table.concat(args,",")..")")
end
else --must be 2 or more
for name,data in pairs(info) do
if args[2]:lower() == tostring(name):lower() then
print(name..": "..data.description)
print("returns: "..string.lower(table.concat(data.returnTypes,',')))---------------------------------NEW ERROR HERE
if #data.args > 0 then
print("args: ")
for _,arg in ipairs(data.args) do
print(" - ("..arg.type:lower()..")"..argName(arg)..": "..arg.description)
end
end
end
end
end
Edited on 31 March 2014 - 08:52 PM