Question about remote interfaces
Question about remote interfaces
One question about remote interfaces. Why function should be created directly in remote.addinterface? When i just use function name as parameter it is not working. Also no errors appears too.
Daniel V. Lenskiy
Re: Modding Info References
It's not required to define stuff inline for remote.addinterface, you just doing something wrong. For example calling said function instead of actually referencing it.Reygan wrote:One question about remote interfaces. Why function should be created directly in remote.addinterface? When i just use function name as parameter it is not working. Also no errors appears too.
Also, wrong thread to post such questions.
Re: Modding Info References
Amm, okayDark wrote: It's not required to define stuff inline for remote.addinterface, you just doing something wrong. For example calling said function instead of actually referencing it.
Also, wrong thread to post such questions.

Could you give me example?
Daniel V. Lenskiy
Re: Modding Info References
Code: Select all
local function print_foo(str)
game.player.print("Foo: "..str)
end
local methods = {
print_me = print_foo,
}
remote.addinterface("FOO", methods)
--remote.call("FOO", "print_me", "BAR")
Re: Modding Info References
Oh, understood, parameter "methods" should be a table with list of assignments, not list of function identifiers.Dark wrote:Code: Select all
local function print_foo(str) game.player.print("Foo: "..str) end local methods = { print_me = print_foo, } remote.addinterface("FOO", methods) --remote.call("FOO", "print_me", "BAR")
Thank you.
Daniel V. Lenskiy
Re: Question about remote interfaces
Alright. Then, second quesion.
Why remote interfaces could not be accessed like this:
This is example from wiki (https://forums.factorio.com/wiki/inde ... interfaces)
Why remote interfaces could not be accessed like this:
Code: Select all
-- check whether there is the "myinterface" interface and whether it contains the "mygetter" function
if remote.interfaces.myinterface and remote.interfaces.myinterface.mygetter then
-- the remote call for the function is safe to use
end
Daniel V. Lenskiy
Re: Question about remote interfaces
Hm, to me 'assignment' doesn't imply "only functions" which (I believe) script interfaces are limited to. What the methods really gets is an associative array, storing functions, indexed by strings (aka names, or identifiers, of those functions); which admittedly, isn't much different from a list in that it stores data (and functions are just callable data in Lua), but it is a bit in that it's easy to get the names of that data (and easy to get data from names).Reygan wrote:parameter "methods" should be a table with list of assignments, not list of function identifiers.
The code given is just checking that the interface was previously defined (and the comment would imply use of remote.call("myinterface", "mygetter")), the reason that addinterface and call are used is because they do extra work to make sure that other mods (and their Lua states) actually know about added interfaces (and it's list of functions). At least, I've assumed so since the interfaces would require C++ to transfer the calls between Lua states; I've never attempted to use just remote.interfaces.x.y(z) (admittedly it'd probably work if called within the script that defined it, probably not for other scripts however).Reygan wrote:Why remote interfaces could not be accessed like this: