I searched and read the forum. I got my very first gadget working with call-in GameStart() and displayed debug message with Spring.Echo ( "msg"). For some unknown reason swapping GameStart() with the MousePress or KeyPress do not display message. I have pasted (to the end of file) these functions to Example Mod game_spawn.lua file to make sure my new script is able to be executed whatsoever.
Code:
function gadget:MousePress(x, y, button) Spring.Echo( "Mouse button pressed! " ) end
I suspect already malfunction with my Spring Engine and OS (though I can select & click to select units inside Example Mod). Am I missing something obvious? Not to mention working Lua MousePress example would be awesome. My Spring Engine version is 0.82.7.1, OS: Win7, Intel-Celeron cpu.
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
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:
-- 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:
-- 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!?
Users browsing this forum: No registered users and 0 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum