Jump to content




api refuses to work


5 replies to this topic

#1 Reinified

  • Members
  • 30 posts

Posted 12 May 2018 - 05: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?

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 12 May 2018 - 05: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()


#3 Reinified

  • Members
  • 30 posts

Posted 12 May 2018 - 05:41 PM

Thanks, the _G system works.

#4 Jummit

  • Members
  • 306 posts
  • LocationJulfander Squad Studio

Posted 13 May 2018 - 05: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.

#5 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 13 May 2018 - 12:44 PM

View PostJummit, on 13 May 2018 - 05:59 AM, said:

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.

#6 Reinified

  • Members
  • 30 posts

Posted 14 May 2018 - 12:06 PM

View PostLupus590, on 13 May 2018 - 12:44 PM, said:

View PostJummit, on 13 May 2018 - 05:59 AM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users