Page 1 of 1

Inter-script communications

Posted: 15 Apr 2007, 05:27
by trepan
I've added a new way for scripts to communicate with each other, UnsyncedXCall().
This communication path only works for unsynced data, but can be used to get data
from any of the following scripts (LuaCob, LuaGaia, LuaRules, LuaUI).

How to use it (example call from LuaUI):

Code: Select all

local a, b, c = Spring.LuaRules.MyCustomFunc(d, e, {f, g, h})
P.S. The unsynced code for LuaCob, LuaGaia, and LuaRules can use the SYNCED
table to gather synced data (as well as any info that they get via the SendToUnsynced()
call).

P.P.S. The other way to provide inter-scripts comms is to use the Rules data that
can be attached to units, teams, and the game. This is a one way street though, and is
intended to be set by the synced code in LuaRules, and read by other scripts. Reading
Rules data is also faster then going through the Spring.LuaXXX.func() calls.

Posted: 15 Apr 2007, 08:13
by AF
It'd be great if groupAI could interface with this...

Posted: 15 Apr 2007, 09:02
by trepan
I'll note that you can also use this feature to write a test widget to
fake call-ins more easily (you could escape to the global namespace
with the 0.74b3 code, but it isn't as clean).

Example (in a LuaUI widget):

Code: Select all

local retval = Spring.LuaUI.KeyPress(97, {}, false)
You can also use it to tell which scripts are active (but in a somewhat
convoluted way, the __call hook is used to return the current state).

Code: Select all

local active = Spring.LuaRules()
if (active) then
  print('LuaRules is running')
end