Some specific Lua modding questions. How much access does it have to game internals?


Jun 13, 2008
First, does anyone know if there are plans for anything like this fine site (the Apolyton python class reference), without which I don't know how I could have done any civ4 modding at all?

Now I have a long list of (seemingly) obscure questions that relate to a mod that I've been brewing up for the last 6 months. Most of these are things that I have done (or know that I could do) in Civ4 via python/xml modding without accessing the sdk. I just want to know whether the same will be possible now with Lua in civ5 or if I need to wait for the sdk. I'm not asking about Lua but about Lua's access to the game internals (and if it can do these things in theory, will there will be sufficient documentation or forum knowledge to make it do so). Please feel free to answer, drop hints as your conscience allows, or blow me off until Tuesday.
  1. Can I change a civilization's leader dynamically during a game (via Lua)?
  2. Can I change leader and/or civilization traits dynamically during a game?
  3. Can I change things like civilization name (the text string) during the game? Or civ color?
  4. Can I change the human player civ (for single player) during a game?
  5. Can my Lua code remember anything from one turn to the next or between saves? (Something I couldn't do in civ4 without the sdk or without some horrible kludge.) For example, my code may need to know whether Excalibur has been pulled from the stone yet (no, this is not really my mod). I don't want my code to have to search all tiles for it or some other nasty solution. I just want to be able to create (via Lua and/or XML) a variable of some sort where I can store this information.
  6. Do I have access to the popup interface and can I implement simple IO with the player (multiple choice selections or requests for short text input)?
  7. Speaking of popups, will I be able to add nice 2D art to my popups in addition to text?
  8. Can I create/destroy units by Lua, or transform to a new type while retaining promotions (pretty trivial but I thought I'd mention it to be complete)
That's pretty much all I need for my grand mod plans.
I'll tell you Tuesday. :)
Just bumping my own thread here now that the NDA has expired. I'm especially interested in the answer to question 5: Can my Lua code remember anything from one turn to the next or between saves? In other words, can I make my own variables and put things in them? (Or is there any other way for modder-created game events to be remembered?) That would open up many possibilities for events, quests, and so on via Lua.
Hrm... I always think in terms of full SDK access, so I can't safely answer any of your questions for LUA only I fear. But for #5 specifically I can say that you can save your own data from LUA into the SQL database.

The Database will "survive" as long as the game is running. As I recall, it even exists after you close the game UNLESS you clear the cache.

When the game loads, I am relatively certain that everything in the SQL database is set back to the defaults listed in the XML. So if you change a value that was initially created by XML, that will be overwritten (ie - base movement of a scout), however, if the value was something that your LUA introduced to the SQL database uniquely, then nothing else would TRY to overwrite it, so it will be maintained across versions.

And for reference in case you try to apply this outside of Civ V, the memory capability is due to the SQL, not the LUA (python + SQL would also be capable of saving data like that)
Thanks xienwolf! That sounds promising. Was there anything analogous to the SQL database in civ4? If so, I managed to do a modest amount of modding without knowing. As far as "SQL", I'm vaguely aware that this is a particular database type/structure/protocol/whatever-you-want-to-call-it. Will I be able to tweak this in various ways with Lua/XML modding without learning a lot of database protocol? Or am I going to have to be a qualified database jockey to even get started?

And for reference in case you try to apply this outside of Civ V, the memory capability is due to the SQL, not the LUA (python + SQL would also be capable of saving data like that)

I think I understand your point here. So is Lua going to act on this database information with more "generic" commands rather than those "pythony"-looking commands I used in civ4 ("pUnit.hasPromotion(blah blah blah)")?
Nothing in Civ 4 was anything like the SQL database. I suppose Pickling might have been as close as anything gets to it, but I didn't deal with that at all. Kael's (FfH) Achievements would be somewhat close to it, as he created a new text file to hold the data for them. But the best answer would be: No.

SQL is basically just a large table (excel file) of data, with entries nested in one another all over the place. Viewing the raw data would hurt your brain, but there are SQL viewers for Firefox and other applications that make it pain-free to browse. LUA can slip in and change any value anywhere, or even add rows/columns however/wherever you would like to.

When the DLL or EXE want to do something, they look at the database for any values they need. LUA has full access to read/write the SQL database at any time (well, any time that the LUA is active), so can change what the DLL/EXE will see the next time around, or can store new things that are only for LUA to look up (since DLL/EXE won't think to look in a new location).

In Python, you used pUnit.hasPromotion(foo), and what "pUnit" really meant was you were asking the DLL to go find out what this particular unit was all about.

In the new setup, I am pretty sure you'll be asking the DLL still about pUnit, as it is a mutable element of the game. But if you wanted to ask about eUnit (the XML entry for that unit type), then instead of asking the DLL with eUnit.hasFreePromotion(foo), you would ask the SQL database (though with roughly similar calls)

The great thing was that in Civ 4, some things about eUnit weren't exposed to be modified by python, especially if added by a modder who hadn't learned that he needs to do so yet. Whereas in Civ 5, any data about eUnit is in the SQL, and thus available instantly to LUA.

In fact, in Civ 4, if I wanted a new tag in the XML, I could modify the Schema and XML files to contain the new tag, and load the game with no issues, but the tag wouldn't DO anything. I could try calling the tag in python to do something, and get no result. But in Civ 5, if I add a new tag to the XML (which includes the Schema in the same file now), and then I try to address that tag in LUA (via SQL), I WILL get results. That alone will make LUA only mods FAR superior to anything that a Python only mod could ever dream of.
Top Bottom