1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Current Status of Lua Modding

Discussion in 'Civ6 - Creation & Customization' started by LeeS, Nov 2, 2016.

  1. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    5,724
    Location:
    Illinois, USA
    After running some tests and playing around with various methods, the following appears to be true:
    1. [fixed by Winter 2016 patch]Lua scripts that are activated in the modinfo file as "GameplayScripts" only load into the game when a new game is started. When a reload of a saved game is conducted, the lua script is not loaded along with the saved game.
      This concerns lua files that are set up in the modinfo file like as this:
      Code:
      <GameplayScripts id="LUA_CODE">
           <Properties>
                <Name>LUA_CODE_GAMEPLAY_CHANGES</Name>
           </Properties>
           <Items>
                <File>LUA_Code.lua</File>
           </Items>
      </GameplayScripts>
    2. Certain API methods (functions) only seem to work in certain context-types. So, for example, the API unit method "GetUnitType()" is not a valid function-name in a "GameplayScripts" context but appears to be valid in a UI context. Similarly, JFD tested and verified that "playerReligion:GetReligionTypeCreated()" is only recognized in a UI context, and when attempted from a "GameplayScripts" context simply causes a fatal syntax error to the lua file. This also explains why using
      Code:
      local iGrassMountains = GameInfo.Terrains["TERRAIN_GRASS_MOUNTAIN"].Index
      TerrainBuilder.SetTerrainType(pChosenPlot, iGrassMountains)
      and similar methods for the ResourceBuilder and FeatureBuilder seem to work in a "GameplayScripts" context but appear not to work in a UI context.
    3. The graphics issues on the main map for terrain alteration coming from a GameplayScript lua from Civ5 are alive and well in Civ6. You can alter the terrain, but in order to get the graphics to update, the player must save and then reload their game.
    4. The good news is that while undocumented as yet there appears to be a pairing of a "set" and a "change" with most "get" methods.

      So, playerReligion:GetFaithBalance() has a paired playerReligion:SetFaithBalance(iNewValue) and playerReligion:ChangeFaithBalance(iChangeAmount).

      These two specific examples have been tested by me and verified to work.
    5. It seems that only lua files that are replacements for existing basegame lua files can be Imported into the VFS system and included in another lua file. New lua files that are Imported and then Included seem not to work according to JFD.
     
    Last edited: Dec 20, 2016
    Angryr, astog, MeerHunter and 2 others like this.
  2. 12monkeys

    12monkeys Chieftain

    Joined:
    Nov 24, 2003
    Messages:
    440
    Location:
    Germany, Europe
    Interresting summary, nice work.

    One shoudl consider to move this into Sub Forum "Modding Tutorials and References"
     
  3. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,918
    Location:
    France
  4. Rob (R8XFT)

    Rob (R8XFT) Ancient Briton Super Moderator

    Joined:
    Aug 11, 2002
    Messages:
    10,636
    Location:
    Leeds (UK)
    Moderator Action: I think whilst LeeS and others are formulating the state of lua modding, it would be good to sticky it in this forum for now, pending a more descriptive thread once more discoveries have been made about lua in Civ 6. I've done this (after speaking with LeeS about it).
    Please read the forum rules: http://forums.civfanatics.com/showthread.php?t=422889
     
  5. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    Do custom UI screens not work yet? I thought I would experiment with one, tried loading as a UserInterface component and game would start to load, jump back to game setup, then I could hit play and game would load, but not custom file. I wasn't sure if there was some setting I was missing, or just doesn't work yet.
    Sorry if this was already covered and I didn't see.

    Edit: I think I may not be properly defining the context. How do I specify the context as ingame and a screen, currently I have name="ingame" in opening context line, and
    Code:
     <Container        ID="Screens">
            <LuaContext ID="TestScreen"                          FileName="TestScreen"                            Hidden="0"  />
        </Container>
    for the lua context, obviously not correct.
    I didn't have problem adding screens in V, but I'm sure I'm missing something obvious, it is early here.:coffee:
     
    Last edited: Nov 21, 2016
  6. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,918
    Location:
    France
  7. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    Thank you, figured it was something simple I was missing (always is:rolleyes:).
     
  8. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,918
    Location:
    France
    Without example, not so simple...
     
  9. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    No, I meant because I had looked through that thread and totally missed the one I needed, and was trying to do it a more complicated way Thanks again.
     
  10. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,918
    Location:
    France
    Anyone found a workaround ?

    I'd really want to use functions available in a gameplay script context after reloading a game...

    There is a "GameCore_Tuner" Lua state listed in the FireTuner which is a "gameplay script context", but can we hook on it ?
     
  11. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    I have tried, also tried using LuaEvents.TunerEnterDebugMode, but no success yet
     
  12. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    Out of curiosity, anyone know how Tutorial.lua is loaded into game? It is listed in the tutorial modinfo as a file, but it's not loaded under components, and I can't find any reference to it. Was just wondering how it was attached, or if was just unused.
     
  13. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    This is just a shot in the dark, but I found this for ui context,
    Code:
    for i, addin in ipairs(Modding.GetUserInterfaces("InGame")) do
            print("Loading InGame UI - " .. addin.ContextPath);
            table.insert(g_uiAddins, ContextPtr:LoadNewContext(addin.ContextPath));
        end
    is it possible to do something similar for gameplayscripts?
     
  14. gyogen2

    gyogen2 Chieftain

    Joined:
    May 8, 2014
    Messages:
    1,201
    Are the modding_loadmod procedures such as
    Code:
    ('Modding_LoadMod', 'AddComponentFile', 'INSERT INTO ComponentFiles(ComponentRowId, FileRowId, Priority) VALUES (?, ?,?)');
    just for adding a file to the mod (which I am not sure why you would want/need to in game, or do they actually add the file into the game?
     
  15. Lord Yanaek

    Lord Yanaek Chieftain

    Joined:
    Aug 15, 2003
    Messages:
    1,444
    Did i understand this correctly as "we can't have Lua scripts affecting gameplay apart from the intialization" or is it just one way of loading them that doesn't work?
    What if i wanted a Lua script for a custom trait like many Civ5 custom civs? Or one that changes yields or adds a dummy building? Are those currently possible as they were in Civ5 or are we limited to UI mods as far as Lua is concerned currently?
     
  16. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    5,724
    Location:
    Illinois, USA
    At the moment we are limited to UI. The other types of lua methods you are referring to require running from a Gameplay script because at the moment many lua commands are context-type dependant, and you need things like as an example a unit-captured event to run from a gameplay context rather than a UI context*. IE, some methods only work in a UI, and are not recognized in a gameplay script, and vice versa. Lots of stuff works in both types of context but it is pretty much hit or miss at the moment for the implementation of what works in which type of lua file.

    * I tried to do that sort of thing as a work-around, but it locked the game because I needed to use a command that was only valid in a gameplay context, and it made the game lock up when it was attempted in a UI file.
    StoredProcedures looks like it is how the game finds and reads the files from the mod(s) and loads them into the game. The issue would appear to be in the game's exe file, since a AgentRansack search shows both the phrases "Modding_LoadMod" and "StoredProcedures" as being what would look like executable code within the game's exe file. Other than that it's all @, $ and # in the same chunk of the exe code.
     
    Last edited: Nov 29, 2016
  17. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    The scenarios implement gameplay changes, but only on first initialize of the game. Thought that was interesting.

    The tutorial does more, but doesn't allow saving.
     
  18. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,918
    Location:
    France
    Yes, I hope it's just because those changes would not be a problem if they are called multiple times, not a sign that gameplay script are designed to run once...
     
  19. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    There is save functionality, with reloading in the tutorial script in the UI directory. But saving is turned off for tutorial, so perhaps they never got it working right?
     
  20. PlotinusRedux

    PlotinusRedux Chieftain

    Joined:
    Jul 11, 2013
    Messages:
    196
    The tutorial cheats, it has Lua files under base\assets that always run, as well as kludges in a number of other files, like Civ6Common.lua[712]:

    Code:
    function IsTutorialRunning()
        local mods = Modding.GetActiveMods();
        if mods ~= nil then
            for i,v in ipairs(mods) do
                if v.Id == TUTORIAL_UUID then
                    return true;
                end
            end
        else
            UI.DataError("Unable to obtain mods table to determine if tutorial is running.");
        end
        return false;
    end
     

Share This Page