LUA - where do I start?

UltimatePotato

Chieftain
Joined
Jul 6, 2014
Messages
24
Location
United Kingdom
I'm looking to get my mod off the ground with some LUA scripting, but I have absolutely no idea where to start. I'm talking about what to do once I make a LUA folder in ModBuddy - what then? I can't find a single tutorial .

What I'm trying to do at the moment is have a special building give +%iNumUnemployed%:tourism:,:c5culture:,:c5unhappy: etc, where %iNumUnemployed% is the number of DEFAULT_SPECIALIST() citizens in the city (unemployed citizens, AKA DEFAULT_SPECIALIST() or SPECIALIST_CITIZEN)

This is the general idea. I recycled this from the source code and modified it for my own needs. nevermind
 
This isn't Lua. Isn't it C++?
Lua is a programming language, there is no single tutorial to teach you how to code. What I would recommend you is to check Lua's website and read their manuals, after you're a bit familiar with how it works, you can start taking on other Modders' mods and trying to read/translate their codes.
Vicevirtuoso's codes are very clean and he usually makes some comments, I made great jumps in coding after reading his stuff. Last Sword and JFD also make some comments, but work with really advanced concepts.
Another thing is to look out for 'simple' stuff to begin with. Look for slight modifications and go from there.


(also, Lua :D)
 
This isn't Lua. Isn't it C++?
Lua is a programming language, there is no single tutorial to teach you how to code. What I would recommend you is to check Lua's website and read their manuals, after you're a bit familiar with how it works, you can start taking on other Modders' mods and trying to read/translate their codes.
Vicevirtuoso's codes are very clean and he usually makes some comments, I made great jumps in coding after reading his stuff. Last Sword and JFD also make some comments, but work with really advanced concepts.
Another thing is to look out for 'simple' stuff to begin with. Look for slight modifications and go from there.


(also, Lua :D)

I'm not really worried about the "how to code part", I can't imagine primitive count X->apply X functions being too difficult.

What I'm asking is - how and where do I set things up before actually doing anything? I can only assume it's Civ5Mod1/Lua/Lua_Script1.lua. The scripts must be in the correct place, they must declare variables somewhere, then there's something to do with a function library (?), and finally they must be loaded by the mod itself. I couldn't find a single tutorial for that, nothing but finished scripts out of context. I don't need help with Lua (yet), I'm asking how/where to add scripts to ModBuddy so that the game actually loads them.
 
This assumption is incorrect. The name is irrelevant, just as it's place inside your mod.
You can put the XML files inside a 'Lua' folder, the art assets inside the 'CatImages' folder and the Lua files in the root folder.

In order to make your mod load the *.lua files, you'll need to tell the mod in the Actions Content tab, setting 'InGameUIAddin' and then choosing your file. I recommend you to do the last part first, because - for some reason - the list of .lua files will vanish once you choose InGameUIAddin from the dropbox (surely you can just type it, but why waste time? :)).

Code:
I can't imagine primitive count X->apply X functions being too difficult.
If only life was so simple.
Yes, some codes will be simple, some others, with theoretically simpler effects will be way more complex, it depends on the Lua API; if there is a method and a call function for the effects you want and the trigger, it'll be easy, if there isn't, you will spend some time circumventing the gap.
 
Lua files in your mod will usually be added via the Content tab as "InGameUIAddin". If they replace an existing lua file (usually happens when modding the UI) VFS will be true and the name of your lua file must match the name of the file being replaced. If your lua file isn't replacing an existing file (usually the case when adding your own effects) VFS will be false and the name of the file can be whatever you want.

95% of the lua you write will be hooked into an event. The event determines when the code is executed. If there isn't an event for what you want, you're generally out of luck.
 
Back
Top Bottom