Lua and Modding questions
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.
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
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.
2. The tutorial itself is a mod! The general project setup for ns2 mods is the following:
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.
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.
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.
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 ). 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:
But in the end you will never get around testing it with some humans.