Question about remote interfaces

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Reygan
Fast Inserter
Fast Inserter
Posts: 177
Joined: Tue Jan 28, 2014 8:42 pm
Contact:

Question about remote interfaces

Post by Reygan »

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

Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

Re: Modding Info References

Post by Dark »

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.
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.

User avatar
Reygan
Fast Inserter
Fast Inserter
Posts: 177
Joined: Tue Jan 28, 2014 8:42 pm
Contact:

Re: Modding Info References

Post by Reygan »

Dark 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.
Amm, okay :)
Could you give me example?
Daniel V. Lenskiy

Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

Re: Modding Info References

Post by Dark »

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")

User avatar
Reygan
Fast Inserter
Fast Inserter
Posts: 177
Joined: Tue Jan 28, 2014 8:42 pm
Contact:

Re: Modding Info References

Post by Reygan »

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")
Oh, understood, parameter "methods" should be a table with list of assignments, not list of function identifiers.
Thank you.
Daniel V. Lenskiy

User avatar
Reygan
Fast Inserter
Fast Inserter
Posts: 177
Joined: Tue Jan 28, 2014 8:42 pm
Contact:

Re: Question about remote interfaces

Post by Reygan »

Alright. Then, second quesion.
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
This is example from wiki (https://forums.factorio.com/wiki/inde ... interfaces)
Daniel V. Lenskiy

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Question about remote interfaces

Post by FreeER »

Reygan wrote:parameter "methods" should be a table with list of assignments, not list of function identifiers.
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:Why remote interfaces could not be accessed like this:
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).

Post Reply

Return to “Modding help”