Code: Select all
function gadget:MousePress(x, y, button)
Spring.Echo( "Mouse button pressed! " )
end
My Spring Engine version is 0.82.7.1, OS: Win7, Intel-Celeron cpu.
Moderator: Moderators
Code: Select all
function gadget:MousePress(x, y, button)
Spring.Echo( "Mouse button pressed! " )
end
Code: Select all
if gadgetHandler:IsSyncedCode() then
--synced stuff goes here:
--creating units, giving resources, ...
else
--unsynced stuff goes here:
--reading keypresses, drawing on screen,...
end
Code: Select all
VFS.Include("LuaGadgets/gadgets.lua",nil, VFS.BASE)
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
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
Are those question you have? I dont really understand what you mean. Bananas!hings to think about: what about syncronized scripts? How to make it work all in one *.lua script? Are you using coconuts!?