31 posts
Posted 12 May 2018 - 06:16 PM
right so I've got an api which refuses to load.
Code: pastebin get kYQqr67d b-client
So basically, os.loadAPI("b-client") returns true but none of the functions are usable. When manually running the program, the API loads and allows usage. Why?
1583 posts
Location
Germany
Posted 12 May 2018 - 06:32 PM
try renaming it; os.loadAPI really just loads all the global stuff the file exposes and stores it in a table inside _G. Typing `b-client.someFunction` is not valid Lua though. Another thing you could do is this:
os.loadAPI "b-client"
_G["b-client"].someFunction()
31 posts
Posted 12 May 2018 - 06:41 PM
Thanks, the _G system works.
327 posts
Location
Julfander Squad Studio
Posted 13 May 2018 - 06:59 AM
BTW, why don't you use require? Its a lot more controllable that os.loadAPI. You can specify the table in which the api is loaded, and you don't have to have unnecessary globals. You can also name the api files as you want without haveing to do the
local api = _G["api.lua"]
thing.
2427 posts
Location
UK
Posted 13 May 2018 - 01:44 PM
BTW, why don't you use require?
Could be running on old CC or wanting to keep compatability. Also might not know about require or how to use it.
31 posts
Posted 14 May 2018 - 01:06 PM
BTW, why don't you use require?
Could be running on old CC or wanting to keep compatability. Also might not know about require or how to use it.
I'm using an older version of computercraft because I need to run it on a 1.8.9 server. Thanks for the tips though!