Extremely basic LUA help is needed
Hi, this is the first time in my life that I try to mod. I have basically no idea what I am doing and unfortunately there are no tutorials for modding Natural Selection 2. (I also have very little experience in programming)
I am still trying to understand the Lua syntax, and would like an answer to this question:
When I open the Client.lua in ns2, I see these lines -
// Precache the common surface shaders.
Shared.PrecacheSurfaceShader("shaders/Model.surface_shader")
Shared.PrecacheSurfaceShader("shaders/Emissive.surface_shader")
Shared.PrecacheSurfaceShader("shaders/Model_emissive.surface_shader")
Shared.PrecacheSurfaceShader("shaders/Model_alpha.surface_shader")
If I understand correctly PrecacheSurfaceShader() is a function, right? Well I go to Shared.lua and I can't see where it is created... I am probably way off in my understanding of something and since it is super basic I want to be corrected.
And another thing... what does ":" mean ? Like here for example -
GetGUIManager():CreateGUIScript("GUIFeedback")
If someone can help me, please be very clear and very basic. Do not assume I know anything at all.
Thanks again for any help
I am still trying to understand the Lua syntax, and would like an answer to this question:
When I open the Client.lua in ns2, I see these lines -
// Precache the common surface shaders.
Shared.PrecacheSurfaceShader("shaders/Model.surface_shader")
Shared.PrecacheSurfaceShader("shaders/Emissive.surface_shader")
Shared.PrecacheSurfaceShader("shaders/Model_emissive.surface_shader")
Shared.PrecacheSurfaceShader("shaders/Model_alpha.surface_shader")
If I understand correctly PrecacheSurfaceShader() is a function, right? Well I go to Shared.lua and I can't see where it is created... I am probably way off in my understanding of something and since it is super basic I want to be corrected.
And another thing... what does ":" mean ? Like here for example -
GetGUIManager():CreateGUIScript("GUIFeedback")
If someone can help me, please be very clear and very basic. Do not assume I know anything at all.
Thanks again for any help
Comments
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local self = GetGUIManager();
self.CreateGUIScript(self,"GUIFeedback");<!--c2--></div><!--ec2-->
You have the right idea about PrecacheSurfaceShader (in terms of where to look), but it is actually a function defined on the C side (it's an engine API call). So you won't be able to find that one in the open-source portion of the game.
It Precaches the files so it can refer to them in the memory in game and don't have to load it (better performance).
The : calls the function from a object, which are declared in a class.
for example,
function Player:GetCrouching()
return self.crouching
end
If "self" is a object from the class Player, you can call self:GetCrouching().
The difference between ":" and "." is an annoying hard to understand quirk of Lua. The best way to think about it is probably "immediacy".
The "." operator is usually used for a field directly on the thing to the left. It's the "close" one. Usually variables: E.G. "MyThingy.name"
The ":" operator is usually used for things not directly on the thing to the left. It's the "far" one. This is usually methods and is the most common one. If you start chaining calls then you'll probably be using ":" as well. E.G. "MyThing:CollectAllNames()"
Your best bet is to use ":" by default and run + check for errors. If it's a variable, or something complex coming from another file/code, consider "." and look through the rest of the file to see how it's being used.
Hope that helps.
Player.GetCrouching(self)
MyThing:CollectAllNames()
is the exact same as
MyThing.CollectAllNames(MyThing)
Which is why I'm recommending ":" whenever possible, unless it's a variable or from a library/other complex piece of code.
Usually it's:
self.ImmediateVariable
self:MyMethod()
Is there a way to search the content of the Lua files?
Say, I want a mod that changes the Team Balance ratio (for example - 2 marines for every 1 alien), how do I find the correct file and location? Do I make an educated guess?
And are those kind of things are as simple as changing a variable's value?
Is there a way to search the content of the Lua files?
Say, I want a mod that changes the Team Balance ratio (for example - 2 marines for every 1 alien), how do I find the correct file and location? Do I make an educated guess?
And are those kind of things are as simple as changing a variable's value?<!--QuoteEnd--></div><!--QuoteEEnd-->
As a fellow noob I will suggest the educated guess path, it leads to exploration and hopefully understanding. In case you are stuck though, I glanced into TeamJoin, Team, and TeamInfo and they might pertain to what you are looking for. More specifically TeamJoin, It was a quick glance, so explore a bit.