Inter-script communications

Inter-script communications

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Inter-script communications

Post 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.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

It'd be great if groupAI could interface with this...
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post 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
Post Reply

Return to “Lua Scripts”