[Solved] GameInfo.CivilizationLeaders["LEADER_JAYAVARMAN"] is nil?

Discussion in 'Mod Creation Help' started by Serp, Sep 30, 2018.

  1. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    I'm currently experimenting with hellblazers UI Notification https://steamcommunity.com/sharedfiles/filedetails/?id=1304210829 mod and trying to fix some problems.

    According to lua.log the following is nil:
    GameInfo.CivilizationLeaders["LEADER_JAYAVARMAN"]
    Why? Was sth about this changed?

    The code is:
    local leaderOne:string = PlayerConfigurations[PlayerID]:GetLeaderTypeName();
    local civTypeO:string = GameInfo.CivilizationLeaders[leaderOne].CivilizationType;

    with leaderOne being LEADER_JAYAVARMAN and the second line results in "attempt to index a nil value". Printing GameInfo.CivilizationLeaders[leaderOne] shows that it is indeed nil.
     
  2. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    CivilizationLeaders is not a Parent table. If you want the text string of the civilization name for a player, just use
    Code:
    PlayerConfigurations[PlayerID]:GetCivilizationTypeName()
    Otherwise to pull the data for a given leader from table CivilizationLeaders it is necessary to loop through the table:
    Code:
    local civTypeO
    for row in GameInfo.CivilizationLeaders() do
       if row.LeaderType == PlayerConfigurations[PlayerID]:GetLeaderTypeName() then
          civTypeO = row.CivilizationType
          break
       end
    end
     
    Last edited: Oct 1, 2018
  3. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    thank you very much, it works :)
     
    Last edited: Oct 1, 2018
  4. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    @LeeS do you know if LeaderType (from PlayerConfigurations[secondPlayerID]:GetLeaderTypeName() ) was changed in GS ?
    Someone reported that it returned "LEADER_ELEANOR_FRANCE" instead of "LEADER_ELEANOR" like I would expect, while the string I want to form should not contain "FRANCE" Locale.Lookup("LOC_" .. leaderOne .. "_NAME"). Can not test it myself, since I do not own GS yet.
     
  5. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    "LEADER_ELEANOR_ENGLAND" -- "LOC_LEADER_ELEANOR_NAME"
    "LEADER_ELEANOR_FRANCE" -- "LOC_LEADER_ELEANOR_NAME"

    They actually use two different leaders, but both leaders use the same "Name" reference.

    So you'll have to grab the LOC_SOMETHING direct and entirely from the Leaders table for column "Name" rather than concatenating.
    Code:
    local sLeaderType = PlayerConfigurations[secondPlayerID]:GetLeaderTypeName()
    local sLeaderNameLOC = GameInfo.Leaders[sLeaderType].Name
    local sTranslatedLeaderName = Locale.Lookup(sLeaderNameLOC)
    Table "Leaders" requires "LeaderType" to be registered in table "Types" as a KIND_LEADER so you can use the direct-access GameInfo method to get the LOC_SOMETHING for the ".Name" column.
     
    Last edited: Mar 9, 2019
    Serp likes this.

Share This Page