Lua Beginners FAQ: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
No edit summary
Knorke (talk | contribs)
dead link, tutorial links more clear
Line 2: Line 2:




This page only tries to answer general questions, for more specific Questions please look at http://answers.springlobby.info/.
This page only tries to answer general questions, for more specific Questions please ask in the forum.






==Q: I'm interested in learning to use Lua with Spring. Where should I start?==
==Q: I'm interested in learning to use Lua with Spring. Where should I start?==
 
A: You can start by reading general Lua tutorials [http://lua-users.org/wiki/LuaTutorial here].  
A: You can start by reading the tutorial [http://lua-users.org/wiki/TutorialDirectory here]. The "Introductory topics" and "Programming in Lua" sections should suffice, in the beginning. After that, you can try editing simple LuaUI widgets, like snd_chatterbox.
After that, you can try following try using Lua in Spring, for example [[Lua:Tutorial_GettingStarted|by following this tutorial.]]





Revision as of 10:46, 27 September 2014

Development < Lua Scripting < Lua Beginners FAQ


This page only tries to answer general questions, for more specific Questions please ask in the forum.


Q: I'm interested in learning to use Lua with Spring. Where should I start?

A: You can start by reading general Lua tutorials here. After that, you can try following try using Lua in Spring, for example by following this tutorial.


Q: Where can I find documentation?

A: On the Lua_Scripting page.

Q: What can't Lua do in the current version of Spring?

A: You can't ...

  • control the ground LOS (but you can set the los status of units!).

Q: How do I open ".lua" files?

A: Notepad or any text editor might be enough. If you are using windows and the text is all garbled, try a programmer's editor. Notepad++ can read Lua files with syntax highlighting.


Q: What is a call-in? And a call-out?

Call-ins are functions defined in your script that Spring calls when a determined event takes place. For example, the gadget:Initialize() call-in is run by Spring when the widget is loaded. Call-outs are functions defined in Spring you can run at whichever moment you desire. For example, when you call Spring.GetUnitTeam(unitID), the engine returns the teamID of the unit identified by "unitID".


Q: What is the difference between a widget and a gadget?

A: A widget is a Lua script that works with LuaUI. A gadget works with LuaRules, LuaCob or LuaGaia. Widgets allow you to customize your interface, and must be unsynced. They can be bundled with the mod or you can save them in your "Spring/LuaUI/Wigets" directory. Gadgets can be synced or unsynced. LuaRules and LuaCob gadgets are usually part of a mod. LuaGaia gadgets should be part of a map. Gadgets can contain both synced and unsynced code.


Q: Where can I find examples?

A: The "Spring\examples\Widgets" directory contains many examples. More can be found in almost every game, especially in the Zero-K game.

Q: Can I reload a script without restarting Spring?

Yes, you can type "/luaui reload" with "/cheats" enabled. More usefull commands.

Q: Why does the print function seem to do nothing?

A: Its output is displayed in stdout. If you have no easy way to see it, you can is Spring.Echo which prints to the ingame chat and infolog.txt.


Q: How do I print the "UnitDefs[unitDefID]" or "WeaponDefs[weaponDefID]" tables? "for k, v in ipairs(t) do print(k, v) end" does not behave as expected.

A: Use "for k,v in UnitDefs[unitDefID]:pairs() do print(k, v) end" instead.


Q: Where can I find help?

A: There is a Lua section in the Spring forums. Probably the most effective way, though, is to join #lua on the lobby.

Q: Who implemented LuaUI, LuaRules and LuaGaia?

A: They were written by trepan.