pPlayer.GetDistricts() not working/broken? And lots of Events in civ 6:)

Ewok-Bacon-Bits

Warlord
Joined
Oct 23, 2016
Messages
169
Hey, I'm not sure if anyone has any clue but I would just like to post this as possibly a warning that this could be broken or maybe I'm missing something but pPlayer:GetDistricts() is always nil. I can confirm that pPlayer:GetCities() is working as well as the for city loop.

I got the code "pPlayer:GetDistricts()" from the city banner/Report UI code so I know that it has to at least be used. If this is broken it seems it could be problematic as we cannot loop through districts. Am I missing something?? I should also say I also tried pCity:GetDistricts() which also failed. Here is the code it is the 8th line having the error:

Code:
function OnPlayerTurnActivated(player, isFirstTimeThisTurn)
    -- PlayerTurnActivated is post DoTurn processing for the beginning of the turn.
    -- Loop Through all of this player's cities if they are under siege subract health (if human do this more depending on difficulty)
    local pPlayer = Players[player]; -- WORKS
if (pPlayer ~= nil) then -- WORKS
    local pCities = pPlayer:GetCities(); -- WORKS
    local playerDistricts = Players[player]:GetDistricts(); -- ERROR HERE
    for i, pCity in pCities:Members() do -- WORKS
        print("**************LOOPING THROUGH CITIES**************"); -- WORKS
    end
end
    -- if (isFirstTimeThisTurn and Game.GetLocalPlayer() == player) then
    -- end
end



function Initialize()
    Events.PlayerTurnActivated.Add(                OnPlayerTurnActivated);
end
Initialize();


On a more positive note there seems to be tooons of events including for combat which I am very excited about!
 
Last edited:
Oops, I was writing too fast I forgot to take out the district loop test in the OP which I just edited out, but ya that would have needed an identifier. Reason is, there is also a pCity:GetDistricts() example also which I was testing out (which was in there) but I got the same nil value. I figure the pPlayer:GetDistricts() skips a step.
 
what are you trying to do?

here's snippet from CitySupport.lua:
Code:
function GetCityData( pCity:table )

	local owner					:number = pCity:GetOwner();
	local pPlayer				:table	= Players[owner];
	local pCityDistricts		:table	= pCity:GetDistricts();
	local pMainDistrict			:table	= pPlayer:GetDistricts():FindID( pCity:GetDistrictID() );	-- Note player GetDistrict's object is different than above.

seems like pPlayer:GetDistricts() only returns city centers, not all districts player owns.
 
Just a thought, does it need an identifier for the city

I noticed all instances with pplayer were either followed by :FindID(districtID)
or were a table, (there was one followed by :Members()

Of course could have been some I missed.

what are you trying to do?

here's snippet from CitySupport.lua:
Code:
function GetCityData( pCity:table )

    local owner                    :number = pCity:GetOwner();
    local pPlayer                :table    = Players[owner];
    local pCityDistricts        :table    = pCity:GetDistricts();
    local pMainDistrict            :table    = pPlayer:GetDistricts():FindID( pCity:GetDistrictID() );    -- Note player GetDistrict's object is different than above.

seems like pPlayer:GetDistricts() only returns city centers, not all districts player owns.

I'll post the UI lua code that I was looking at when I get home. I didn't notice that comment in the code that is interesting good to know the difference. I wanted to loop through specifically city districts so that I could use the pDistrict:IsUnderSiege() and pDistrict:GetDamage().
 
Code:
        for _,district in pPlayer:GetDistricts():Members() do
            if (district ~= nil and district:IsComplete() and district:GetType() == SPACE_PORT_DISTRICT_INFO.Index) then
                bHasSpaceport = true;
                break;
            end
        end

Code:
    local pPlayer = Players[ playerID ];
    if (pPlayer ~= nil) then
        local pPlayerDistricts:table = pPlayer:GetDistricts();
        for _, district in pPlayerDistricts:Members() do

These two snippets are from WorldRankings.lua and CityBannerManager.lua. I'm not aware that I'm doing anything differently.

I also tested this (below) which also didn't work in accordance to the WorldRanking example.

Code:
    for _,district in pPlayer:GetDistricts():Members() do -- ERROR
        print("**************LOOPING THROUGH CITY DISTRICTS**************");
    end

I also attached the mod if anyone wants to play around with it, you will need the tuner.
 

Attachments

I thought it may have been the include files after you suggested it but it still didn't do it after taking the same include files from the respective examples.

I'm guessing it has to do with the function or event not liking GetDistricts() so that is good to know.
 
Back
Top Bottom