My Lua Pain... Documented :)

Quacksparkler

Chieftain
Joined
Nov 10, 2020
Messages
1
Hi All,
I just wanted to drop in to say hi, I've been playing since the early days of Civ IV but never really got heavily into modding it outside XML tweaks.

I'm looking to improve my Lua and figured may as well start with Civ VI, it's got a decent console which most games don't.

I'm a dev by trade so figured I may as well spin up some breadcrumbs on GitHub Pages for anyone who wants to also have a stab but isn't sure where to start, least its not a complete waste of time then I doubt I will spend a long time on a major mod.

Right now its got info on SDK setup, FireTuner setup & how to make a Hello World Lua mod.

https://jonathanturnock.github.io/civ-vi-modding/docs/

Happy to also accept contributions and feedback obviously. Happy Modding!
 
If nothing else, I just wanted to encourage you to continue.

I am someone that already mods via XML/SQL, but have no knowledge of the Lua framework - neither in the Civilization context, nor the wider context. But I am keen to learn and I will be keenly following your tutorials, as they materialise! So please keep them going, even if only for me :-)
 
If nothing else, I just wanted to encourage you to continue.

I am someone that already mods via XML/SQL, but have no knowledge of the Lua framework - neither in the Civilization context, nor the wider context. But I am keen to learn and I will be keenly following your tutorials, as they materialise! So please keep them going, even if only for me :-)
Erm. Well. There's this whole thing with multiple chapters on lua for Civ6 in my signature.

I'm hoping since I am off work all week to add some more stuff related to Modifiers but if I get time I intend to expand the lua chapters some as well.

@Quacksparkler : I like the visual look of your tutorial on the modbuddy download etc, but I would quibble with attempting to test lua scripts outside of the game environment. The version of lua used by the game is higher than lua5.1 (since Civ6 recognizes the table.count(tablename) function), but the version used by the game does not recognize a multitude of functions available in the more recent "general" versions of lua. Additionally, the lua used in Civ6 is entirely dependant on the context within which the script executes. Lua scripts executed from an AddGameplayScripts action-type have a completely separated and sandboxed API as compared to those running from a UserInterface context. Some functions are shared and exposed to both processing-thread contexts, but the majority are not -- they depend entirely on the context from which executed and return nil function errors when attempted from the incorrect context-type. Fireturner adds to this "fun" because it is a hybrid API and can often lead people to think that their script will work when in fact it will not once executed via a User Interface or AddGameplayScript context.

I generally direct people who want to experiment with how variables of different types (boolean, text, integer, table) work, how for and while loops work, and how lua table iterating (traversing) work in lua to the online lua demo page here (Internet Lua Demo Page ) http://www.lua.org/cgi-bin/demo

Once you start shoving functions specific to Civ6 into an lua script, though, the lua demo page will not work because it does not understand Players[iPlayer]:GetUnits() or anything else specific to the Civ6 lua environment.

------------------------------------

All that quibbling having been said, please keep working on your documentation / tutorial. The more good references and sources that exist the better for the modding community.


[edited again because of annoying forum auto format "fixing"[/]
 
Last edited:
Erm. Well. There's this whole thing with multiple chapters on lua for Civ6 in my signature.

Ha, you are absolutely right - I didn't necessarily say no such resource existed; just admitting that I personally have devoted no time to learning it!

Good prompt, though - I think I will read those sections of your guide and try and implement something representative and simple along the way.
 
The version of lua used by the game is higher than lua5.1 (since Civ6 recognizes the table.count(tablename) function), but the version used by the game does not recognize a multitude of functions available in the more recent "general" versions of lua.
AFAIK Civ6' Lua is Havok script.

I don't know if we have access to all the debugging capabilities it offers (I've seen some lua-related dll added in the moddbuddy folders with an old patch IIRC), but I know that one of its specificities is to allow you to use variable typing if you want.

example
Code:
local currentBuildingType :string = GameInfo.Buildings[buildingIndex].BuildingType;

Using that should generate an explicit error in the log if, for example, you assign a number to a variable when you were expecting a string, and can't understand immediately why 300 lines later you always get "false" as a result of a comparaison and you know that sometime it should be "true"...
 
Back
Top Bottom