21 posts
Posted 03 May 2015 - 09:32 PM
im trying to make a program where i can detect methods on a side of the computer, heres what ive got:
for k,v in ipairs(peripheral.call(read(),read()))
print(k,"; ",v)
end
when i do this it acts like:
> programname
right
getMethods()
it errors because the getMethods() i specify is a string, when i need a normal variable with the same text. how would i convert that so it would work?
// ill figure this below out so please ignore
Also, i want to make a program for a mining machine, but i cant figure out the redpower compatability, and the wiki was of no help to me there.
Edited on 03 May 2015 - 07:34 PM
1023 posts
Posted 03 May 2015 - 10:05 PM
Your problem is actually how peripheral.call works. You will want to type "getMethods" instead of "getMethods()". For peripheral.call you just pass it the name, you do not have to actually try and call it.
957 posts
Location
Web Development
Posted 03 May 2015 - 11:22 PM
Like valithor said, you don't actually need to convert it to a variable.
peripheral.call() only needs strings as arguments
If you are still curious about converting strings to variables, check out the lua program that comes with ComputerCraft
(You know, the one that you run by typing 'lua', the interactive command prompt)
Edited on 03 May 2015 - 09:23 PM
8543 posts
Posted 04 May 2015 - 04:30 AM
And the correct way to call it is peripheral.getMethods(side) anyway, you don't call getMethods as a peripheral method.
957 posts
Location
Web Development
Posted 05 May 2015 - 12:20 AM
And the correct way to call it is peripheral.getMethods(side) anyway, you don't call getMethods as a peripheral method.
Aren't there peripheral mods that add functions to their peripherals like 'getMethods()'?
1023 posts
Posted 05 May 2015 - 12:57 AM
And the correct way to call it is peripheral.getMethods(side) anyway, you don't call getMethods as a peripheral method.
Aren't there peripheral mods that add functions to their peripherals like 'getMethods()'?
I believe there are, but from the context of his post he wants peripheral.getMethods as Lyqyd said.
8543 posts
Posted 05 May 2015 - 03:51 AM
And the correct way to call it is peripheral.getMethods(side) anyway, you don't call getMethods as a peripheral method.
Aren't there peripheral mods that add functions to their peripherals like 'getMethods()'?
Yes, or "listMethods", and those mods are, in my opinion, Doing It Wrong (TM).
21 posts
Posted 07 May 2015 - 04:11 AM
thanks people, i can make my program now :D/>
21 posts
Posted 07 May 2015 - 05:39 AM
it didnt work
the first one was obvious, peripheral.getMethods(side)
but the second one is peripheral.call(read(),read())
for some reason peripheral.getMethods("front") works but
peripheral.call("front","getMethods") does not
why i want to make call work is so that i can have a visual; i can see what methods there are and then see what ones there are then see those ones too, thats why i dont want to make it peripheral.getMethods()
Edited on 07 May 2015 - 03:42 AM
8543 posts
Posted 07 May 2015 - 06:32 AM
That's not how it works. Use peripheral.getMethods() to get a list of methods available on a peripheral, then call them with peripheral.call or use peripheral.wrap and call the methods from the table it returns.
When you use peripheral.call, you're calling methods that the actual peripheral is providing, whereas peripheral.getMethods is part of the peripheral API (like peripheral.call). You can't just decide you want to call functions from the peripheral API as if they're methods on the peripheral itself and expect it to work.