SQL and/or XML and/or LUA ?

richardsvensson

Chieftain
Joined
Sep 25, 2010
Messages
32
Hello everyone,

I'm just learning how to mod civ vi, (I haven't really been modding any previous versions of Civ) so I need a short introduction to the relationship between SQL, XML and LUA.

I have been able to make a few changes to the game with SQL scripts, and some time ago I also made a few changes by editing XML files. So far I have no experience of LUA.

My question is not how to learn these things, but rather how they relate to each other? Can I do all the modding with just one of them (and it's more a matter of taste which one I choose)? Or should I use a combination? Maybe some parts of the mod is done with SQL scripts and other parts by editing an XML-file?

Thanks!
 
XML, SQL, and LUA: The Differences
(this info is true for both Civ5 and Civ6)​

  1. The game has a database of information that defines Civics/Policies, Techs, Civilzations, Units, etc.
  2. This database is really just text entries in what is very like a spreadsheet of rows and columns (this is where <Row> in xml comes from)
  3. SQL and XML add new information to or alter existing information within the database. XML is often seen as easier to understand for beginners. But other than the fact that SQL can do a few things XML cannot, and that SQL can allow dynamically reading what is already added to the database before "deciding" whether to make a change to the database, the two languages (XML and SQL) are essentially just different flavors for adding to or altering what is already there in the database from the game's Firaxis-supplied files.
  4. This is true even though XML and SQL make use of differing syntax. They are both just methods to write to the same database.
  5. LUA however is a completely different animal.
    • It has its own language
    • while it can freely read from data in the game's database, it has only limited capability to alter what already exists within the game's database
    • LUA code is only executed (with certain very specific exceptions) after the player is into the game (ie, after they've started a new game or reloaded a saved game and the game loading screen closes).
    • LUA is dynamic to the conditions currently in the game, whereas SQL and XML are static to current conditions in the game. Once SQL/XML set-up the database, that is it, the database is locked and SQL/XML are no longer "operating". LUA however can react to whether a player moves a unit on the game map, whether they found a city, etc., and create different effects within the game based on whose unit it was that moved or which player founded a city.
    • For example LUA can detect the founding of a city as the city is founded, and can for example add +5 gold to a player's treasury if and only if the player is Rome, is a Human player, and has at least five other cities. SQL/XML cannot do this sort of dynamic effecting of the game.
  6. LUA changes the Game-Status, not the Database. The Game-Status can be wildly different on Turn #1000 than it is on Turn #1, with all the units, cities, improvements, wonders, and what-not that will be different on Turn #1000 than on Turn #1. But the game's underlying Database will not be altered between Turn #1 and Turn #1000.

Spoiler for experienced modders :
yes, yes, I know the Civ6 modifiers & effects systems available to XML/SQL in the database can do all sorts of magic, but let's not muddy the waters of understanding what these different languages are for
 
Last edited:
XML, SQL, and LUA: The Differences
(this info is true for both Civ5 and Civ6)​
...

Thanks! This was exactly the kind of basic info I was looking for!
Now I understand the different logics of XML/SQL on the one hand and LUA on the other hand. While XML/SQL change the starting conditions of the game, LUA changes the 'rules' of the game.

So, it looks like I definitely should learn LUA then. I guess the website www.lua.org is the best start. Any other (more civ related) reading that might be helpful are very much appreciated!
 
....and a follow up question: I still have to create XML-files for the text (for example description of civ, description of building etc.)? Or can that be done by SQL script as well?

I have looked around in the database but haven't found anywhere to store the text (only the reference to the text, as I understood it).
 
Now you drifted into the lands of the exceptions, as it were.

Civ6 modding is a bit kludgey in its implementation as far as I am concerned as compared to the state civ5 is currently in. Civ6 requires definitions of text to be made within seperate xml or sql files to "gameplay" xml/sql code. So when defining a new text key you would need a file like as this, called in this example GameText.xml:

Contents of GameText.xml:
Code:
<GameData>
	<LocalizedText>
		<Row Tag="LOC_TECH_HAMBURGERS_NAME" Language="en_US">
			<Text>Hamburgers</Text>
		</Row>
	</LocalizedText>
</GameData>
Then you must specifically tell the game that GameText.xml is to be loaded to the LanguageLocalization database rather than the GamePlay database, like this in the mod's modinfo file if you are manually writing the mod:
Code:
<Mod id="45ad7053-9a78-4ce2-98da-f4cae0b063dc" version="1">
  <Properties>
    <Name>ModBuddy Test</Name>
    <Description>Testing whether this mod or any mod can long endure</Description>
    <Teaser>Testing whether this mod or any mod can long endure</Teaser>
    <Authors>Lee</Authors>
  </Properties>
  <InGameActions>
    <UpdateText id="NewAction2">
      <File>XML/GameText.xml</File>
    </UpdateText>
  </InGameActions>
  <Files>
    <File>XML/GameText.xml</File>
  </Files>
</Mod>
If you are using modbuddy you need that action setup as here as I am doing with a test mod:
https://www.dropbox.com/s/tb421pzjyc9egj2/Civ6_ModBuddy_TextActions.jpg?dl=0
My text file has a different name in this image than GameText.xml. In this image I was using a text filename of EarlyBump_Text.xml as I recall.
 
Last edited:
Also be aware that with civ6 some people are reporting trouble getting SQL code to work for table IconDefinitions, which requires it's own action type within modbuddy. So you might possibly run into trouble using SQL for defining text tags.

If all else fails just use XML in table <LocalizedText>. SQL won't really gain you much of anything anyway because historically all the localization tables have ever wanted you to do is delete (DELETE FROM or <Delete Tag="XYZ"/>), add new (INSERT or <ROW>), Update (UPDATE or <Update>), or Replace (INSERT OR REPLACE INTO or <Replace).
 
Also be aware that with civ6 some people are reporting trouble getting SQL code to work for table IconDefinitions, which requires it's own action type within modbuddy. So you might possibly run into trouble using SQL for defining text tags.

...

Ok. Thanks to you I'm making some progress here. :)
The mod now consists of the .modinfo file as well as one .sql (with some data changes) and one .xml with the text information.

At the moment I have only one problem (hopefully easy to fix though). The created civilization don't show up in the list of playable civilizations when starting a new game. When I check the database, I can find the civilization and the three leaders, and they are all part of the Civilopedia.

Any suggestions on what the problem could be?

(Sorry for asking all these questions, it's just that I really want to get started with the fun part of the modding as soon as possible). :)
 
@LeeS Hello!
It's an interesting theme. Search machine gave me this link =)
I have a question with mod which I working about.

So, I do the player-colored textures for the units. And I can easy to update the base of file-links with SQL to replace old textures to colored-new.
But! I want to make this like an option. In start menu Player will choose the option of "Player Colored Units". And only after this I want the XML or SQL made the changes in data-base.

How to take status of option chosen in Start Menu, from SQL or XML to make a decision of altering files or not?
-OR-
How to execute XML or SQL overriding, from the LUA which can uderstand the status of option?

Thanks for your modding work.
 
*OH*, I'm glad this popped up. This explains so much about why something I tried didn't work at all until I moved all the text entries into the localization file. I wrote the descriptions into the same page as the new promotion tree.
 
Top Bottom