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

Can't get this code to run

Discussion in 'Mod Creation Help' started by criZp, Oct 17, 2020.

  1. criZp

    criZp Emperor

    Joined:
    Jul 19, 2013
    Messages:
    1,757
    Location:
    Nidaros, Norway
    I'm trying to make a change to the civics tree so that increased trade/spy capacity appears as those blue icons that are also used for increased envoys/governors/. There's a file called CivicsTreeIconLoader_GovernorSlot.lua:

    Code:
    include("InstanceManager");
    include("CivicUnlockIcon");
    
    g_ExtraIconData["MODIFIER_PLAYER_ADJUST_GOVERNOR_POINTS"] = {
        IM = InstanceManager:new( "CivicUnlockNumberedInstance", "Top"),
     
        Initialize = function(self:table, rootControl:table, itemData:table)
                local instance = CivicUnlockIcon.GetInstance(self.IM, rootControl);
                instance:UpdateNumberedIcon(1, "[Icon_Governor]", Locale.Lookup("LOC_HUD_CIVICS_TREE_AWARD_GOVERNOR"), itemData.Callback);
            end,
    
        Reset = function(self)
            self.IM:ResetInstances();
        end,
    
        Destroy = function(self)
            self.IM:DestroyInstances();
        end
    };
    
    I copied the code and made some changes. Here's CivicsTreeIconLoader_TradeCapacity.lua:

    Code:
    include("InstanceManager");
    include("CivicUnlockIcon");
    
    g_ExtraIconData["MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_CAPACITY"] = {
        IM = InstanceManager:new( "CivicUnlockNumberedInstance", "Top"),
     
        Initialize = function(self:table, rootControl:table, itemData:table)
                local instance = CivicUnlockIcon.GetInstance(self.IM, rootControl);
                instance:UpdateNumberedIcon(1, "[Icon_TradeRoute]", "+1 trade capacity", itemData.Callback);
            end,
    
        Reset = function(self)
            self.IM:ResetInstances();
        end,
    
        Destroy = function(self)
            self.IM:DestroyInstances();
        end
    };
    
    The governor-file executes here when "tIconData" is created, and I thought that the trade-file should do too but it doesn't:

    Code:
    -- Include extra icons in total unlocks
        local extraUnlocks:table = {};
        local hideDescriptionIcon:boolean = false;
        local cachedModifiers:table = m_CachedModifiers[kData.CivicType];
        if ( cachedModifiers ) then
            for _,tModifier in ipairs(cachedModifiers) do
                local tIconData :table = g_ExtraIconData[tModifier.ModifierType];
                if ( tIconData ) then
                    hideDescriptionIcon = hideDescriptionIcon or tIconData.HideDescriptionIcon;
                    table.insert(extraUnlocks, {IconData=tIconData, ModifierTable=tModifier});
                end
            end
        end
    
    This code is from the function AddAvailableCivic in CivicsChooser.lua.

    I have added CivicsTreeIconLoader_TradeCapacity.lua to expansion2 like this:

    (Expansion2/UI/Loaders folder)
    Screenshot (19).png

    (Expansion2.modinfo ImportFiles)
    Screenshot (20).png

    (Expansion2.modinfo Files)
    Screenshot (21).png

    Does anyone have a clue?
     
  2. criZp

    criZp Emperor

    Joined:
    Jul 19, 2013
    Messages:
    1,757
    Location:
    Nidaros, Norway
    It works now, just had to restart the game lol.
     

Share This Page