How can I change a text string mid-game?

Desertmoongw

Chieftain
Joined
Oct 29, 2014
Messages
22
Location
Cascadia
I'm currently working on a mod where depending on what government you are and what civilization you are, your name (among other things) will be different, for example Chiefdom America would be The Thirteen Colonies. Maybe I'm just stupid, but I can't figure out a way to change a piece of text in the middle of a game. I know how to change a piece of text completely, but I need it to be able to be changed as soon as the player changes government. For clarification, when I say a text string or a piece of text, I'm specifically referring to the "LOC_CIVILIZATION_NAME_DESCRIPTION" type strings, not the UI elements that present these, as going through every instance in which your civilizations name is shown would be tedious and sure to back fire if a user decides to use any other UI mod.
 
You can't change what is in the database for a particular LOC_SOMETHING_OR_OTHER without changing it in xml or sql at game loading.

In civ5 there was a capability to do what you are talking about through lua-scripting commands, but I'm not sure there is an equivalent in civ6, and as I recall in civ5 these were really just "virtual" changes that only had effect for the remainder of that game session.
 
You can't change what is in the database for a particular LOC_SOMETHING_OR_OTHER without changing it in xml or sql at game loading.

In civ5 there was a capability to do what you are talking about through lua-scripting commands, but I'm not sure there is an equivalent in civ6, and as I recall in civ5 these were really just "virtual" changes that only had effect for the remainder of that game session.

Ah, Oh well. Would it then instead be possible to change what the LOC_TEXT is used in? Like changing the Name part of <Row Name="LOC_TEXT_A"/> to "LOC_TEXT_B" mid-game? I'm not very experienced in modding Civ 6, so apologies if this is something simple.
 
It's essentially the same issue. Everything in the game's database is loaded before the game session actually begins as part of the process of loading the game's base files and any code from expansions or dlc or mods, and is static from that point.

Thereafter xml and sql code is "done" as it were, and any changes like you woud want to do mid-game would have to be done directly in the UI files that control what is displayed to the user.
 
Short answer:

you'll have to edit the UI files, or, when possible, use ContextPtr:LookUpControl to set specific text without replacing a vanilla file.


Long answer:

That won't help you in this case, but the database is also loaded as "GameInfo" in game, which is not locked and can be edited using Lua, this allows a few UI element to be changed midgame, for example, this:

Code:
GameInfo.Buildings["BUILDING_GRANARY"].Name = "Place to store grain"

works when opening a city screen (but not the tech tree or the civilopedia, they would require a refresh)

For civilizations AFAIK the UI calls PlayerConfigurations[playerID]:GetCivilizationShortDescription() to display a civ name in most place, and there is no PlayerConfigurations[playerID]:SetCivilizationShortDescription("Kingdom of Scyhtia") available. (there is a SetLeaderName function if you want to change a player name)

So this:
Code:
GameInfo.Civilizations["CIVILIZATION_SCYTHIA"].Name = "Kingdom of Scyhtia"

Will only show the change when making a deal for example.

Note that when GameInfo is used to get a name (or even when using PlayerConfigurations[playerID]:SetLeaderName("Queen Tomyris")), you may still need to force a refresh on various parts of the UI to show the change immediately, and you'll also have to handle your GameInfo changes on reload, they won't be saved.

Note that as they use GetCivilizationShortDescription instead of GameInfo.Civilizations.Name, it could mean that SetCivilizationShortDescription is planned, just not implemented yet.
 
Short answer:

you'll have to edit the UI files, or, when possible, use ContextPtr:LookUpControl to set specific text without replacing a vanilla file.


Long answer:

That won't help you in this case, but the database is also loaded as "GameInfo" in game, which is not locked and can be edited using Lua, this allows a few UI element to be changed midgame, for example, this:

Code:
GameInfo.Buildings["BUILDING_GRANARY"].Name = "Place to store grain"

works when opening a city screen (but not the tech tree or the civilopedia, they would require a refresh)

For civilizations AFAIK the UI calls PlayerConfigurations[playerID]:GetCivilizationShortDescription() to display a civ name in most place, and there is no PlayerConfigurations[playerID]:SetCivilizationShortDescription("Kingdom of Scyhtia") available. (there is a SetLeaderName function if you want to change a player name)

So this:
Code:
GameInfo.Civilizations["CIVILIZATION_SCYTHIA"].Name = "Kingdom of Scyhtia"

Will only show the change when making a deal for example.

Note that when GameInfo is used to get a name (or even when using PlayerConfigurations[playerID]:SetLeaderName("Queen Tomyris")), you may still need to force a refresh on various parts of the UI to show the change immediately, and you'll also have to handle your GameInfo changes on reload, they won't be saved.

Note that as they use GetCivilizationShortDescription instead of GameInfo.Civilizations.Name, it could mean that SetCivilizationShortDescription is planned, just not implemented yet.
Thank you very much for the detailed response! Hopefully I'll be able to find a way to get the idea working with this and some work arounds.
 
Top Bottom