This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
martin's profile picture

peripheral :48 expected string

Started by martin, 21 December 2014 - 03:57 AM
martin #1
Posted 21 December 2014 - 04:57 AM
i need help with a program i have it working but it wont run right… i have a copy of it if needed:


for k, v in periperal.getMethods(cofh_thermalexpansion_energycell_0)
) do local table = {}
  table[1] = periperal.wrap(cofh_thermalexpansion_energycell_0)
   end
for i = 1, #table do
table[i].method(cofh_thermalexpansion_energycell_0)
  end
if true
then print (("..k..")"..v..")
end
if false
then print "ERROR"
  end
Edited by
Lyqyd #2
Posted 21 December 2014 - 07:26 AM
Moved to Ask a Pro.

I added the code for you inside that code block, rather than attaching it as a download. Also, that code could not possibly generate that error, so please be sure you've copied and pasted it or verify, character, by character, that what you've retyped is what was on the computer. That said, it looks like you are lacking quotes around your networked peripheral names:


--# use this:
peripheral.getMethods("cofh_thermalexpansion_energycell_0")
--# not this:
periperal.getMethods(cofh_thermalexpansion_energycell_0)
Dragon53535 #3
Posted 21 December 2014 - 10:06 AM
Your code will not run at all and will error at every turn.
It won't do what you want, and will completely fail.

Your code with marked errors.

for k, v in periperal.getMethods(cofh_thermalexpansion_energycell_0))--[[#Too many ) ]]-- do --# Each of your cofh_thermalexpansion_energycell_0 should be enclosed in "
  local table = {} --#This is only available inside here, don't use the variable name table, it kills the whole table api
  table[1] = periperal.wrap(cofh_thermalexpansion_energycell_0) --# This will happen every single time the loop runs
end--#This is the end of the loop, table gets deleted.
for i = 1, #table do --#This will error, as table doesn't exist inside of it's scope.
  table[i].method(cofh_thermalexpansion_energycell_0)--# Again, won't work, table isn't defined, and doesn't have a method function
end ---#End of the loop, this is technically fine
if true then
  print (("..k..")"..v..") --#Not valid concatenation
end
if false then --# Will never run.
  print "ERROR"
end
Edited on 21 December 2014 - 09:22 PM
MKlegoman357 #4
Posted 21 December 2014 - 01:53 PM
In Lua if you are giving a function only a string or a table you don't need paranthesis. This is a totally valid Lua code:


print "Hello world"
print {1, 2, 3}
Dragon53535 #5
Posted 21 December 2014 - 10:22 PM
Well then, something learned new every day.
TheOddByte #6
Posted 21 December 2014 - 10:25 PM
- Snip -
Well, some would call it a bad habit( *cough* TheOriginalBIT *cough* ) and I agree, it's better getting used to using parentheses.