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

"Variable Out Of Sync" related to every UI Code issues

Discussion in 'Civ5 - Creation & Customization' started by Cat-du-fromage, Mar 23, 2020.

  1. Cat-du-fromage

    Cat-du-fromage Warlord

    Joined:
    Nov 17, 2018
    Messages:
    177
    Gender:
    Male
    I'm currently facing a big problem of sync when making a mod using button.

    It seems in multiplayer all fonction using a registerCallBack do not sync when using by someone other than the Host.

    it causes desync and everything made by the function is cancelled.

    Is this normal?

    here is a sample of the code:
    Code:
    function OnLiberateColonyClicked( cityID )
        local player = Players[Game.GetActivePlayer()];
        local pCity = player:GetCityByID(cityID)
        Controls.ConfirmLabel:LocalizeAndSetText( "TXT_KEY_COLONY_CONFIRM_LIBERATE", pCity:GetName() );
        Controls.Confirm:SetHide( false );
        Controls.BGBlock:SetHide( true );
       
        Controls.Yes:SetVoid1( 0 );
        Controls.Yes:SetVoid2( cityID );
        Controls.Yes:RegisterCallback( Mouse.eLClick, OnYes );
    end
    
    function OnYes( type, iValue )
        Controls.Confirm:SetHide(true);
        Controls.BGBlock:SetHide(false);
        -- Liberation
        if( type == 0 ) then
            ColonyLiberation( iValue );
            MaybePeace(iValue)
            OnClose();
        -- Apply Tax Change
        elseif ( type == 1 ) then
        local iPlayer = iValue
            local iTaxRate = PercentToTaxValue( Controls.GeneralTaxSlider:GetValue() );
    
            GeneralTaxeTIMER(iPlayer, iTaxRate)
            OnClosingOK()
        end
    end
    
    function ColonyLiberation(cityID)
    
    local pPlayer = Players[Game.GetActivePlayer()];
    local eCity = pPlayer:GetCityByID(cityID)
    
    
    local pColonyX = eCity:GetX()
    local pColonyY = eCity:GetY()
    local plot = Map.GetPlot(pColonyX, pColonyY)
    local pCity = plot:GetPlotCity()
        if PlayerRebelCity(pPlayer) ~= nil then
        local pRebel = PlayerRebelCity(pPlayer)
        pRebel:AcquireCity(pCity, false, true)
        else
        Game.DoSpawnFreeCity(pCity)
        end
    end
    Log here:
     

    Attached Files:

  2. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,756
    Location:
    Illinois, USA
    It's hard to say because (a) you are using CBP which completely alters the game engine, and (b) you are running a multiplayer work-around (I assume) in order to have mods in multiplayer for a game that is notorious for not playing well with mods when running multiplayer.

    But I think the problem is in using the code in multiplayer, to be honest. In Single-Player "Game.GetActivePlayer()" returns the player ID number of the human player, which is normally player ID # "0", but as I recall in multiplayer games it returns the ID # of the Host, which is usually also Player ID number "0". If anyone else clicks the button in a normal multiplayer game this would be a recipe for instant de-synch because the game is going to retrieve the ID # of the Host rather than the player who actually clicked the UI button. In a hotseat game, as I recall, "Game.GetActivePlayer()" returns the player ID # of the player currently in the "Hotseat".

    This sort of problem is then compounded by the fact that city ID #s are shared. Every player's original capital city always has the same ID # so long as they still own the city: once the city is captured by someone else, the city ID # alters to the first available City ID # slot available to that player. So there can be a city with ID # 1234 belonging to player # 0, and another with the same ID # belonging to player #1, and another belonging to player # 2, and so on.
     
  3. Cat-du-fromage

    Cat-du-fromage Warlord

    Joined:
    Nov 17, 2018
    Messages:
    177
    Gender:
    Male
    thanks for your reply, i tested everything to make it work but the fact that "Game.GetActivePlayer()" always return the host ID is a pain in the ass......

    fun fact some of firaxis base code like move great work from city to city have the same issues , causing a lot of desync -_-

    Do you have a tricks to return the ID of the current user of the UI other than "Game.GetActivePlayer()"?

    EDIT: I found Events.GameplaySetActivePlayer.Add(OnTechPanelActivePlayerChanged);, using by firaxis for the tech choice (who strangly do not cause desync) maybe is this the key?
     
    Last edited: Mar 27, 2020

Share This Page