Understanding Lua
For years myself and many others have been coding modes in amx or sourcemod. Now with NS2 we need to learn a new language; however, Lua appears to be very different in manors of syntax ect than either sourcemod or amx. Does anyone have an example of a simple sourcemod script written in Lua?
This would make it very easy for those of us familiar with SM to then compare the two programs and thus learn Lua syntax and methodology.
This would make it very easy for those of us familiar with SM to then compare the two programs and thus learn Lua syntax and methodology.
Comments
You can start with some basic lua tutorials.
Here's a list of some tutorials:
<a href="http://lua-users.org/wiki/TutorialDirectory" target="_blank">http://lua-users.org/wiki/TutorialDirectory</a>
You can test lua code here (online lua compiler):
<a href="http://www.lua.org/demo.html" target="_blank">http://www.lua.org/demo.html</a>
You can also just read through the code and look after the functions if you dont understand them.
It's more difficult to understand the complete ns2 code cause its complex, there are a lot of functions and
not a really good documentation of everything.
So start the game with decoda, add a brake point and jump through some code will help to understand which function is getting called etc.
Or look at some mods like the SoulCatcher or other small mods (they're not as complex as the complete ns2 code and maybe a bit easier to understand).
If you have any knowledge of programming, you will find NS2 very easy to modify. Just open up decoda and dive into the code. The syntax is ridiculously easy to learn. There are lots of mods around, I'd recommend downloading them and comparing them with the NS2 code too.
The best way though is to just jump in and start experimenting, you'll be amazed at what you can produce.
pulling some of the existing mods from steam workshop & then checking out the lua code in the C:\Users\<username>\AppData\Roaming\Natural Selection 2\Workshop folder
There are some simple ones - murphy's balance mod .. soulcatcher2000 that can show you how to integrate a mod & aren't overwhelming in complexity.
edit: as with any language the biggest hurdle is learning the APIs, so check out as much code as possible. e.g. open the project ns2.deproj in decoda & use shift control F a lot :)