Knorke I appreciate your input.

Demo showing these scripts in action under post as attachement.
Solution to thread problem, before bit backstory. My version of Spring Engine is 0.82.7.1, OS is Win7, data of this post is 11 august 2011.
Unix users pay attention to upper- and lowercase! Change file names accordingly.
Press F11 in-game to access widget menu, F12 to take screenshot and F5 to toggle SpringUI off/ on.
moddir is your independent game folder (archive). For example valid
folder name for game is: your_game.sdd
widgets are for user interface (UI), they are stored in:
moddir/LuaUI/widgets/your_script.lua
gadgets are for creating everything on game, they are stored in:
moddir/LuaRules/gadgets/your_script.lua
gadgets need gadget framework to work which is *.lua file in:
moddir/LuaRules/main.lua
main.lua file content:
Code: Select all
VFS.Include("LuaGadgets/gadgets.lua",nil, VFS.BASE)
Create it yourself if you do not have it.
Widgets get loaded into game only if they are in correct folder.
No widget in gadget folder and vice versa.
To the point, in moddir/LuaUI/widgets/ add this *.lua script:
Code: Select all
-- default Lua script info block
function widget:GetInfo()
return {
name = "MousePress event",
desc = "Invoked by MousePress call-in to forward message",
author = "InDesign",
date = "Aug 11, 2011",
license = "GNU GPL, v2 or later",
layer = 5,
enabled = true -- this script enabled by default?
}
end
-- Spring.SendLuaRulesMsg is Spring Engine function
-- MessageDispatcher is name, same naming is used in
-- Alpha Domination game by Sunspot
-- You can store functions into variables, isn't it cool?
local MessageDispatcher = Spring.SendLuaRulesMsg
-- MousePress is a Lua API function, full list can be found:
-- http://springrts.com/wiki/LuaCallinReturn
function widget:MousePress(x, y, button)
-- When mouse press event happens we send message out
-- to invoke RecvLuaMsg event
MessageDispatcher("mousepress")
end
In moddir/LuaRules/gadgets/ add this *.lua script:
Code: Select all
-- default Lua script info block
function gadget:GetInfo()
return {
name = "MousePress action",
desc = "Invoked by RecvLuaMsg call-in to aquire message",
author = "InDesign",
date = "Aug 11, 2011",
license = "GNU GPL, v2 or later",
layer = 5,
enabled = true -- this script enabled by default?
}
end
-- By sending message with Spring.SendLuaRulesMsg also
-- named MessageDispatcher in event_mouse_press.lua
-- RecvLuaMsg call-in gets executed
function gadget:RecvLuaMsg(msg, playerID)
-- With more functions sending messages it becomes important
-- to do identity check
-- Spring.Echo is function to display messages on screen
if msg == "mousepress" then Spring.Echo("Mouse pressed!") end
end
Test your game. Things to think about: what about syncronized scripts? How to make it work all in one *.lua script? Are you using coconuts!?