[Tutorial] Using LuaExporter to build custom CSV files


The intention of this tutorial is to be a starting guide to making custom scripts for LuaExporter and making your own structured data files that you can use later.
Using custom LuaExporter scripts could simplify analyzing stats in challenges and allow for easier implementation of additional calculations based on various exportable data.
This tutorial will teach you how to find useful data, make a script that puts a selected range of data into a CSV file, and as a bonus we will make a Python script that will automatically combine all exported CSVs into one file.


There are a couple of things you want to make sure you have before we start:

  • LuaExporter (duh)
  • A program that can import CSV data such as Microsoft Excel or Google Sheets (inspecting files with a text editor also works to an extent)
  • A good text editor or IDE to write Lua and Python (for the bonus part) scripts. Standard notepad works but you should really get yourself Notepad++ or better yet Visual Studio Code or similar
  • Python (for the bonus part)

Getting started

When you first run LuaExporter it will create an example script in C:\Users\user\AppData\Local\AutomationGame\luaExporter\ .scripts
The first thing you want to do is create a copy of the example script and open it.
You don’t really need to pay attention to most of the things in the file, you can just remove the .car export if you want to by deleting the line or commenting it out by putting “–” to the left of it
The most important part can be found at the bottom

This is where you handle your data and write it to a file (or several).
“Files” is a dictionary, where the key is the file name and the value is the file content.
The example creates a string with some exported data and writes it to a file called “trimDataExport.txt”

Fetching the data

Now let’s change things around and export the data we want. In order to do that we need to find what kind of things we can export in the first place. Luckily, there are a few ways to do that, for example you can check out the exporter SDK documentation.
Alternatively, you can press F9 in Automation, navigate to “Table Explorer” and find most of the data there.
Following the images below, let’s find where the sportiness stat is:

And there it is, now let’s reconfigure our script to build CSV data and add the sportiness value there, I’ll also add a few other things

Remember that CSV files are just lines of text which can be interpreted as a column, where each row is a line and each column is separated via a comma.
You can write column names here as the first line, then separate it out with a newline character ("\n") before writing the data, however I will be doing that separately later in the bonus part.
Remember that you can do your own calculations in this same script, a little googling of how to do the thing you want in Lua will let you do your wonders.
And now it’s time to run our script.

Running the script

Select luaExporter in the Automation exporter screen, for convenience later down the line you can add some sort of prefix to the folder name so that we can easily find it later:

I will be using “CSVT - [Car Name]”.
Next you will be asked to select your script. Select it and click OK to run it.

If you’ve made an error it will pop up once you run the script, or (if you are reading this once the error message has been removed from the game) the file will not export and you will have to check the game’s log to see where you’ve made a mistake.
If everything went well though you can open the export folder (C:\Users\user\AppData\Local\AutomationGame\luaExporter) and observe the data

Bonus: Automating output merging with Python

Let’s create a Python file in the luaExporter directory.
I will make 2 ways to give the script files to use for merging:

  1. Dragging the file we want to merge onto the python script file;
  2. Merging all files in folders that start with “CSVT”.

We will need to import a few standard libraries.

Now let’s create our main function and set up the template for our 2 ways of running
If you drag a file onto the script file it will run the script with the path of that file as the second argument, otherwise there won’t be one.

Let’s also make a function that makes the column name row which we will be adding as the first line to the CSV file, we write things in the same order we did in the Lua script and separate them with commas (and no spaces).

And now we make the function that will create the CSV file or just write to it if it already exists
The function takes in a parameter “lines”, those are our rows of exported data.

And now let’s write our functions that take in the data, first from a provided file and then from all folders that start with “CSVT”:

Now let’s run it and if no error occurred we will get this folder with a file inside it:


And now we can import this file into something like Excel:


And this sums up the basic use of LuaExporter with some additional automation. I hope this allows more people to dive into the use of the plugin to come up with new easier and/or creative ways of using these features.


What does this achieve?

This achieves teaching people how to use LuaExporter to assist them in running challenges.

Like what can it do? It explains the process but not what are the possibilities with this.

It explains how to get and organize various data from automation.
What one does with that data is entirely up to their imagination. The sky is the limit.