Chili:Tutorial Dynamic Label Content: Difference between revisions
No edit summary |
|||
| Line 43: | Line 43: | ||
} | } | ||
end | end | ||
</ | </pre></code> | ||
Revision as of 15:03, 19 June 2011
Dynamic label updating
Preparation
Having windows with labels on screen is a fun thing. Although you probably want to change the contents of those labels if some event happens ingame. For this tutorial we are going to change a label everytime a unit gets destroyed.
as before we are going to establish a basic structure for our code. However we are going to need 4 scripts now.
- LuaRules\Gadgets\Includes\messages.lua - LuaRules\Gadgets\Includes\utilities.lua - LuaRules\Gadgets\units_destroyed_counter.lua - LuaUI\widgets\gui_chili_unitdestroyedwindow.lua
In the messages.lua we are going to put global constants that will prefix interface messages between the engine rules code and the widget ui code. Utilities.lua will contain handy utitliy functions like tokenizing strings or array debug code. Units_destroyed_counter.lua will be used as engine rule code to keep track of the amount of units destroyed. Gui_chili_unitdestroyedwindow.lua will contain the code to display the amount of units destroyed.
Units_destroyed_counter.lua
We will start this page the same way as we did with hello world.
-- INCLUDES
VFS.Include("LuaRules/Gadgets/Includes/utilities.lua")
VFS.Include("LuaRules/Gadgets/Includes/messagetypes.lua")
-- CONSTANTS
local DEBUG = true
-- MEMBERS
local unitDestroyedCounter = 0
-- SYNCED CONTROLS
local Echo = Spring.Echo
-- SCRIPT FUNCTIONS
-- GADGET CODE
function gadget:GetInfo()
return {
name = "units destroyed counter",
desc = "Keeps track of the destroyed units in game (including unfinished units, that timeout)",
author = "Sunspot",
date = "2011-06-19",
license = "GNU GPL v2",
layer = -50,
enabled = true
}
end