Understanding Lua

ZEROibisZEROibis Join Date: 2009-10-30 Member: 69176Members, Constellation
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.

Comments

  • CamronCamron Join Date: 2011-01-06 Member: 76356Members
    Look at the NS2 source. Start at something familiar like a weapon and then move up the class hierarchy.
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    edited October 2012
    Lua is not hard to learn,
    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).
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    I haven't any real experience in programming, and I never bothered to learn LUA, because NS2 lua is very different. However I have been able to make some very big full game modifications. GorgeCraft and Proving Grounds are two examples of very different variations on the NS2 code base.

    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.
  • extolloextollo Ping Blip Join Date: 2010-07-16 Member: 72457Members
    edited October 2012
    ^

    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 :)
Sign In or Register to comment.