• Civilization 7 has been announced. For more info please check the forum here .

Need Help with determining a YieldType inside a Table


Feb 9, 2016
Today I've (hopefully) got an easy conundrum that needs solving:

So I'm trying to use Lua to display a Yield Type from a Table on my custom Top Panel (for this example, let's use Belief_HolyCityYieldChanges), but the results usually come up with too much or nothing at all.

A sample code snippet:
        local iHolyCityCultureBelief = 0;
        local iFirstYield = 0;

        for pBelief in GameInfo.Beliefs() do
            local iBelief = pBelief.ID;
            local thisBelief = GameInfo.Beliefs[iBelief];
            local beliefCondition = "BeliefType = '" .. thisBelief.Type .. "'";

            for rPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
                local rPlayer = Players[rPlayer];
                if (pPlayer == rPlayer) then
                    if (rPlayer:GetReligionCreatedByPlayer() >= 1) then
                        local rReligion = rPlayer:GetReligionCreatedByPlayer();
                        for i,v in ipairs(Game.GetBeliefsInReligion(rReligion)) do
                            local belief = GameInfo.Beliefs[v];
                            if (belief ~= nil) then
                                -- Holy City Culture Yield
                                for row in GameInfo.Belief_HolyCityYieldChanges( beliefCondition ) do
                                    if (row.YieldType) then
                                        local yield = GameInfo.Yields[row.YieldType];
                                        if (yield == YieldTypes.YIELD_CULTURE) then
                                            if (iFirstYield < 1) then
                                                iHolyCityCultureBelief = iHolyCityCultureBelief + row.Yield;
                                                iFirstYield = iFirstYield + 1;

What the above code is supposed to do is grab the Culture YieldType (the only other yield that works with this particular function is Faith), but depending upon how I've tried programming it, the code either won't return with any Yield at all, or will add all possible Yields together; not distinguishing between them one way or the other. I've actually had this problem with other areas in the code before now, but those have at least had work-arounds (the Trait_YieldChangesPerTradePartner effect for Morocco's trait comes to mind); not so the case with this code, and I'd like to have a definitive fix for this problem moving forward. If anyone could help me achieve one, I'd be most grateful.

Also, I should mention the iFirstYield integer I've rigged up is a quick-fix solution I came up with. It will display the Yield correctly, but it assumes that the Culture yield is programmed before the Faith yield (or any other yield for that matter, should someone be playing with a Mod that enables them), and as I should not depend upon the whims of other modders being a constant with my own, I wanted a more dependable solution for this issue.

Well, I went ahead and used te quick-fix solution I had (or a variation of it, which works well enough). Thanks to all who took the time to look this thread over. However, if anyone does eventually come up with a solution for this, and would like to share, then I'd be most greatful for the effort! ;)
Top Bottom