Jump to content




[solved]help! peripherals listMethods not working correctly, works in lua but not in actual code


2 replies to this topic

#1 CreeperGoBoom

  • Members
  • 91 posts

Posted 23 November 2016 - 08:39 AM

ok so im trying to create a program that will document anything i want using a turtle

for each peripheral i am having problems with, listMethods shows up in getMethods
in lua listmethods works fine, but in my code it returns the error: attempt to index ? a nil value

why would it work in lua but not in code for the same code? [confused]

the error randomly gets thrown for both line 36 and 39

here is the code

http://pastebin.com/uNZDxbNJ

this is driving me absolutely nuts, any help is appreciated, cheers!!

Edited by CreeperGoBoom, 23 November 2016 - 09:13 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 November 2016 - 09:06 AM

You're defining "device" at a time when "side" is "" - so wrapping fails, and "device" ends up as nil. You hence can't index into it to look for a "listMethods" function, as the error tells you.

Best to forget about listMethods anyway, mind you. There's no guarantee all peripherals will offer it, and peripheral.getMethods() already does the job.

#3 CreeperGoBoom

  • Members
  • 91 posts

Posted 23 November 2016 - 09:09 AM

thanks for the quick answer Bomb Bloke, but im looking for the additional info that listMethods provides such as the parameters for each method, getMethods only lists the methods without parameters, any ideas on how to accomplish this?

edit: nvm i just removed the local side = ""
and moved the corresponding local peripheral wraps to just below side = read()

for anyone who was having my problem here is the fixed code

Spoiler

Cheers @Bomb Bloke [thumbsup]
you my friend are seriously one of the best coders I know

Edited by CreeperGoBoom, 23 November 2016 - 09:15 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users