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

Passing variables to an API from a program using that API

Started by frogger72, 21 January 2014 - 05:27 PM
frogger72 #1
Posted 21 January 2014 - 06:27 PM
Hi, I need to know if its possible for a program to pass variables to an API that the program is using.
For instance, in my API I want to use 'modem' that was declared in my program:
modem = peripheral.wrap(settings.modemside)
but my API doesn't know what 'modem' is, so I can't use modem.transmit() inside my API.
CometWolf #2
Posted 22 January 2014 - 12:11 AM
Having the api wrap the modem would be the logical solution…

api.modem = modem
This will change the api's local modem variable to whatever the variable modem in your current script points to.
robhol #3
Posted 22 January 2014 - 12:50 AM
Not really local.
I think the most "correct" solution here would be to pass the modem to any function that uses it.
CometWolf #4
Posted 22 January 2014 - 12:58 AM
api.modem is not the same as _G.modem, ergo it is local to the api enviroment.

But yeah, passing the peripheral table sounds like a better solution
Edited on 21 January 2014 - 11:59 PM