Lua and Modding questions

corundcorund Siberia Join Date: 2015-04-13 Member: 203372Members
edited May 2015 in Modding
Hello!
Instead of making new topic for each question i will post them in this single thread and hope that somebody will answer :)

Question1:
Lua does not have classes or reserved keyword "class" but i regularly come across lines like this:
class "Tutorial" (Entity)
What is this? I failed to find "class" definition if it is a function. There is a file class.lua in "core" folder but it does not contain definition of the "class". I'm new in Lua, probably it is stupid question.

Comments

  • corundcorund Siberia Join Date: 2015-04-13 Member: 203372Members
    Question2:
    I want to make singleplayer mod and looks like existing Marine Tutorial is the correct place to start with. How could i load modified version of MarineTutorial.lua? I put modified file in MODDIR/lua and MODDIR/tutorial/lua and tried to hot-load mod but nothing happens. In the same time modified version of client.lua loads correctly from folder MODDIR/lua.
  • GhoulofGSG9GhoulofGSG9 Join Date: 2013-03-31 Member: 184566Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Reinforced - Supporter, WC 2013 - Supporter, Pistachionauts
    edited May 2015
    1. These "lua classes" are a custom lua interpreter construct of spark handled directly by the C++ code. Think about them for now as lua classes with some extras (e.g. later you can fetch all created entities of one class).

    2. The tutorial itself is a mod! The general project setup for ns2 mods is the following:
    • lua – contains all game code files ( .lua files)
    • models – contains all models the game uses (.model, .material and .dds files)
    • maps – contains all map files (.level files )
    • materials – materials and textures used by the maps ( .material and .dds files )
    • sound – contains all sound files the game uses (.fsb, .fev and .soundinfo files )
    • ui – contains all textures used by the ingame ui (.dds files )
    • screens – contains all images used as background for the loading screen ( .jpg files )
    • shaders – contains all shaders the game uses (.fx, .screenfx, .hlsl and .shader files )
    • cinematics -contains all cinematics the game uses ( .cinematic and .dds files )
    • gamestrings – contains text files which are used to translate in-game text. ( .txt files )

    So to overload lua files put them into the lua folder of your mod. The mounting order should be core -> ns2 -> tutorial -> mods -> your mounted project, it's actually core -> ns2 -> mods -> your mounted project -> tutorial :(.

    BTW be aware that hot-loading works these days different than most old tuts explain it. Personally i would suggest you to use the "recreate server" - method to load code changes.
  • IronsoulIronsoul Join Date: 2011-03-12 Member: 86048Members
    @GhoulofGSG9 thanks for posting this information, I'm going to add it into my cheatsheet.
  • corundcorund Siberia Join Date: 2015-04-13 Member: 203372Members

    So to overload lua files put them into the lua folder of your mod. The mounting order should be core -> ns2 -> tutorial -> mods -> your mounted project.

    How could i overload tutorial files? If i put modified files of tutorial in my mod lua folder - it does not work.
  • GhoulofGSG9GhoulofGSG9 Join Date: 2013-03-31 Member: 184566Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Reinforced - Supporter, WC 2013 - Supporter, Pistachionauts
    edited May 2015
    corund wrote: »

    So to overload lua files put them into the lua folder of your mod. The mounting order should be core -> ns2 -> tutorial -> mods -> your mounted project.

    How could i overload tutorial files? If i put modified files of tutorial in my mod lua folder - it does not work.

    My bad, as it seems the tutorial folder gets actually mounted last if you start it via the tutorial menu button. A way around this is to copy the complete tutorial folder into you mod folder and just work with it as normal mod (just be aware that the tut is kinda hard-coded for ns2_docking).

    I will see if we can fix the mounting order in future builds.
  • corundcorund Siberia Join Date: 2015-04-13 Member: 203372Members
    My bad, as it seems the tutorial folder gets actually mounted last if you start it via the tutorial menu button. A way around this is to copy the complete tutorial folder into you mod folder and just work with it as normal mod (just be aware that the tut is kinda hard-coded for ns2_docking).

    I will see if we can fix the mounting order in future builds.

    Please, don't waste your time on this feature! There are so many things much more important that wait for fix or implementation. I will find way how to modify tutorial, probably the best way is to copy tutorial to mod folder like you said.
  • corundcorund Siberia Join Date: 2015-04-13 Member: 203372Members
    edited May 2015
    Question #3:
    How to understand what type of result function returns and what arguments it accepts in lua? Looking at the definition does not help much and very often definition is missing, probably these functions defined in engine in C language.

    Question #4:
    How can i figure out what lua files are loaded first? Is there any diagram showing dependencies between classes in NS2?

    Question #5:
    Do you debug NS2 lua code? How do you do this and is this useful?
  • GhoulofGSG9GhoulofGSG9 Join Date: 2013-03-31 Member: 184566Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Reinforced - Supporter, WC 2013 - Supporter, Pistachionauts
    edited May 2015
    corund wrote: »
    Question #3:
    How to understand what type of result function returns and what arguments it accepts in lua? Looking at the definition does not help much and very often definition is missing, probably these functions defined in engine in C language.

    Question #4:
    How can i figure out what lua files are loaded first? Is there any diagram showing dependencies between classes in NS2?

    Question #5:
    Do you debug NS2 lua code? How do you do this and is this useful?

    3. Most times the result type is clear out of the context (at least for me after working more than 1k hours with the code base :D ). If something is a FFI function and defined in the engine it should show up in the ns2/docs/api files ;) Otherwise you can use Lua type() method and object:GetClassName()

    4. Such a diagram doesn't exist iirc. Ns2Docs shows you the overall class-structure which should be already really helpful. For more loading order details you have to dig throw the Client/Server/Predict.lua Script.Load() references. Ofc you could also hook into that function and let it print out the loading order for you if needed.

    5. Well writing code without debugging is quiet impossible. Here my steps of debugging:
    1. Syntax check (via IDE syntax highlighter or LuaC)
    2. Some code analysis (via internal IDE Lua Analyzer and CheckStyle)
    3. Unit testing via LuaUnit
    4. Functional testing (running ns2 with my mod's code mounted and testing the functions with bots,running a bot game)

    But in the end you will never get around testing it with some humans.
Sign In or Register to comment.