[Solved] Is there no way to make library for control.lua?

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1197
Joined: Wed May 18, 2016 4:55 pm
Contact:

[Solved] Is there no way to make library for control.lua?

Post by Mooncat »

Just to make sure, is there no way to make shared functions that can be used by control.lua from another mod?

Bob's library shows that it is possible to make library for data.lua, but I can't get it to work when making my library for control.lua. If I add require "the file from the library mod" in control.lua, it complains for no such file. I have tried
  • require "file-name"
  • require "mod-name/file-name"
  • require "__mod-name__/file-name"
but none of them works. if I don't add require, the function simply does not exist. :?

Edit:
The answer is: you can actually make library mod for control.lua.
The trick is to use remote.add_interface in your library mod, and use remote.call in the other mods.
See the API doc for more details.
Thanks DedlySpyder for the answer.
Last edited by Mooncat on Wed Aug 03, 2016 6:33 pm, edited 1 time in total.
User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 254
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: Is there no way to make library for control.lua?

Post by DedlySpyder »

You would have to use remote calls, as each mod is in its own sandbox, so they don't see each other besides using remote calls.

Bob's is different because the data stage of the game shares everything amongst the mods (I assume that also applies to his functions, though I've never looked too far into it)
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1197
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Is there no way to make library for control.lua?

Post by Mooncat »

DedlySpyder wrote:You would have to use remote calls, as each mod is in its own sandbox, so they don't see each other besides using remote calls.

Bob's is different because the data stage of the game shares everything amongst the mods (I assume that also applies to his functions, though I've never looked too far into it)
I see. Totally forgot about the remote call. Thanks for reminding me. I will give it a try!
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1197
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Is there no way to make library for control.lua?

Post by Mooncat »

Yes, remote call can do the trick. Thanks a lot.
Post Reply

Return to “Modding discussion”