<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.fightorder.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Lua%3ATutorial_GettingStarted</id>
	<title>Lua:Tutorial GettingStarted - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.fightorder.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Lua%3ATutorial_GettingStarted"/>
	<link rel="alternate" type="text/html" href="https://www.fightorder.net/wiki/index.php?title=Lua:Tutorial_GettingStarted&amp;action=history"/>
	<updated>2026-04-21T04:02:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://www.fightorder.net/wiki/index.php?title=Lua:Tutorial_GettingStarted&amp;diff=1170&amp;oldid=prev</id>
		<title>Qrow: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://www.fightorder.net/wiki/index.php?title=Lua:Tutorial_GettingStarted&amp;diff=1170&amp;oldid=prev"/>
		<updated>2026-02-24T05:52:58Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:52, 23 February 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Qrow</name></author>
	</entry>
	<entry>
		<id>https://www.fightorder.net/wiki/index.php?title=Lua:Tutorial_GettingStarted&amp;diff=1169&amp;oldid=prev</id>
		<title>luainter&gt;Masterbel: &lt;syntaxhighlight&gt; doesn&#039;t appear to be working, so for the time being I&#039;ve subbed it out with &lt;pre&gt;&lt;code&gt;</title>
		<link rel="alternate" type="text/html" href="https://www.fightorder.net/wiki/index.php?title=Lua:Tutorial_GettingStarted&amp;diff=1169&amp;oldid=prev"/>
		<updated>2023-06-21T03:30:45Z</updated>

		<summary type="html">&lt;p&gt;&amp;lt;syntaxhighlight&amp;gt; doesn&amp;#039;t appear to be working, so for the time being I&amp;#039;ve subbed it out with &amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Engine_Development|Development]] &amp;lt; [[Lua_Scripting|Lua Scripting]] &amp;lt; {{FULLPAGENAME}}&lt;br /&gt;
&lt;br /&gt;
Here are some examples of small widgets, with useful code to get you started! &lt;br /&gt;
&lt;br /&gt;
To play with each example, place the code into a &amp;quot;my_new_widget_name.lua&amp;quot; file in your Spring/LuaUI/widgets dir (create it if not already present) and run Spring with any game. Your widget should then appear ingame!&lt;br /&gt;
&lt;br /&gt;
To see many more examples, check out the LuaUI/widgets directory of the games in [[Gamedev:PublicRepos|PublicRepos]]. &lt;br /&gt;
&lt;br /&gt;
Note that every widget (and gadget) must include a GetInfo() callin, but all other callins are optional.&lt;br /&gt;
&lt;br /&gt;
==Example 1==&lt;br /&gt;
The &amp;quot;hello world&amp;quot; example, with a ticking clock.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
function widget:GetInfo()&lt;br /&gt;
   return {&lt;br /&gt;
      name         = &amp;quot;Name as shown in widget list&amp;quot;,&lt;br /&gt;
      desc         = &amp;quot;Description as normally shown in tooltip&amp;quot;,&lt;br /&gt;
      author       = &amp;quot;It could be you!&amp;quot;,&lt;br /&gt;
      date         = &amp;quot;now&amp;quot;,&lt;br /&gt;
      license      = &amp;quot;PD&amp;quot;, -- should be compatible with Spring&lt;br /&gt;
      layer        = 0,&lt;br /&gt;
      enabled      = true&lt;br /&gt;
   }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local helloWorld = &amp;quot;I STARTED LOOK AT ME JIM!&amp;quot;&lt;br /&gt;
local toggle&lt;br /&gt;
&lt;br /&gt;
function widget:Initialize()&lt;br /&gt;
   Spring.Echo(helloWorld)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function widget:Update()&lt;br /&gt;
   if (toggle == true) then&lt;br /&gt;
      Spring.Echo(&amp;quot;TOCK&amp;quot;)&lt;br /&gt;
      toggle = false&lt;br /&gt;
   else&lt;br /&gt;
      Spring.Echo(&amp;quot;TICK&amp;quot;)&lt;br /&gt;
      toggle = true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example 2==&lt;br /&gt;
How to make stuff happen when units do stuff.&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
function widget:GetInfo()&lt;br /&gt;
   return {&lt;br /&gt;
      name         = &amp;quot;Unit Announcer&amp;quot;,&lt;br /&gt;
      desc         = &amp;quot;Units are proud to be alive&amp;quot;,&lt;br /&gt;
      author       = &amp;quot;Some guy&amp;quot;,&lt;br /&gt;
      date         = &amp;quot;I don&amp;#039;t know why we include dates&amp;quot;,&lt;br /&gt;
      license      = &amp;quot;GPLv2 or later&amp;quot;,&lt;br /&gt;
      layer        = 0,&lt;br /&gt;
      enabled      = true&lt;br /&gt;
   }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local machoUnits = {}&lt;br /&gt;
&lt;br /&gt;
function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID)&lt;br /&gt;
  Spring.Echo(&amp;quot;HELLO&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  local humanName = UnitDefs[unitDefID].humanName&lt;br /&gt;
  local numWeapons = #UnitDefs[unitDefID].weapons&lt;br /&gt;
  local plural = numWeapons~=1 and &amp;quot;s&amp;quot; or &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  Spring.Echo(&amp;quot;I am unit &amp;quot; .. unitID .. &amp;quot;. I am a &amp;quot; .. humanName .. &amp;quot;.&amp;quot;)&lt;br /&gt;
  Spring.Echo(&amp;quot;I have &amp;quot; .. numWeapons .. &amp;quot; weapon&amp;quot; .. plural .. &amp;quot;.&amp;quot;)&lt;br /&gt;
  if numWeapons&amp;gt;0 then&lt;br /&gt;
    machoUnits[unitID] = true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam)&lt;br /&gt;
  machoUnits[unitID] = nil&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
function widget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, projectileID, attackerID, attackerDefID, attackerTeam)&lt;br /&gt;
  if machoUnits[unitID] then return end&lt;br /&gt;
&lt;br /&gt;
  local n = math.random(3,10)&lt;br /&gt;
  local ow = &amp;quot;O&amp;quot;&lt;br /&gt;
  for i=1,n do&lt;br /&gt;
    ow = ow .. &amp;quot;W&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
  Spring.Echo(ow)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example 3==&lt;br /&gt;
Something actually useful.&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
function widget:GetInfo()&lt;br /&gt;
  return {&lt;br /&gt;
    name      = &amp;quot;Stop means Stop&amp;quot;,&lt;br /&gt;
    desc      = &amp;quot;Cancels Self D orders when unit is given a stop command&amp;quot;,&lt;br /&gt;
    author    = &amp;quot;enotseulB&amp;quot;,&lt;br /&gt;
    date      = &amp;quot;GPL v2 or later&amp;quot;,&lt;br /&gt;
    license   = &amp;quot;Feb 2015&amp;quot;,&lt;br /&gt;
    layer     = 0,&lt;br /&gt;
    enabled   = true  &lt;br /&gt;
  }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local CMD_STOP = CMD.STOP&lt;br /&gt;
&lt;br /&gt;
function widget:UnitCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)&lt;br /&gt;
    if cmdID ~= CMD_STOP then return end&lt;br /&gt;
    if not unitID then return end&lt;br /&gt;
    if teamID ~= Spring.GetMyTeamID() then return end&lt;br /&gt;
&lt;br /&gt;
    if (Spring.GetUnitSelfDTime(unitID) &amp;gt; 0) then&lt;br /&gt;
        Spring.GiveOrderToUnit(unitID, CMD.SELFD, {}, {})&lt;br /&gt;
    end &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
[[category: Lua]]&lt;/div&gt;</summary>
		<author><name>luainter&gt;Masterbel</name></author>
	</entry>
</feed>