Trying to understand context switching b/t GamePlayScripts and UI - can it be mixed?

DARPA

Chieftain
Joined
May 15, 2020
Messages
5
Hi all, I've lurked for a bit on here and I'm stuck on something that I suspect is just confusion on high-level approach. I am creating a mod wherein I'm interested in looking at several characteristics for multiple in-game objects. Cities are a good example here - I have the following rough pseudo-code to approximate what I'm doing here...
-------------------------------------------------------------------
function GenerateCityData(player, civName)
for idx, pCity in player:GetCities():Members() do
***(I Want To Get Gold Here.... Culture yield,bunch of other stuff, Etc)***
end
end

function OnGlobalTurnCompleted(iTurnNumber)
local pAlivePlayers = PlayerManager.GetWasEverAliveIDs()
for i, id in pairs(pAlivePlayers) do
PlayerID = Players[id]
(more *stuff*)
GenerateCityData(pPlayer, shortName)
end
end

Events.OnGameTurnEnded.Add(OnGlobalTurnCompleted)
--------------------------------------------------------------------
(This file is built with "GamePlayScript" in modbuddy)

Now, in ChimpanG's listing of LUA objects and their context, I've noticed he differentiates between IN GAME and IN CONTEXT(UI). I know for a fact that I am adding my above code to the IN GAME portion (essentially just adding an extra functionality at the end of a turn) through the Events.OnGameTurnEnded.Add() functionality, but in LeeS Civ 6 guide to modding, he mentions that data can be shared between these contexts (but doesn't really specify how exactly). It seems that for some data items - City:GetCulture():GetCultureYield() for example - can only be grabbed from this ui context. How can I mix and gather this data from both contexts? Is my approach fundamentally wrong or am I just missing something? Been at it for about 2 or 3 days now but I've been hung up on this part. Thank you in advance!
 
And for advanced modding please note that UI context use cached values, and Script context use mostly* direct core values.

Could cause unexpected values depending on the events you hook into.

* looking at you pUnit:GetDamage() !
 
Got it. So just to clarify, does this mean that I have to create a separate UI file, based on say an end turn or a start turn event, and then create a series of methods that all populate the exposed members table? Furthermore it seems that in that thread they pointed out that if you are using any sort of UI modification, I must also add an actual panel or physical item into the UI, even if it is not presented to the user? Is this an assumed requirement? If so, is there a really barebones tutorial on the bare minimum for creating say...an invisible UI element? I am not looking to present anything to the user on either context so a UI element is not really a requirement for me. Thank you so much!
 
Capture.PNG


This is the current Status of my code. I have attempted to follow the guide in the other post, but I still receive the same error. I have included the empty XML for UI setup purposes (or to put it in "context"). It seems that all of the above still returns this error for me...

Runtime Error: C:\Users\DARPA\Documents\My Games\Sid Meier's Civilization VI\Mods\dataScraper\UIHelper.lua:7: function expected instead of nil
 
It's because you're taking the city object in script then passing it to UI context, but it still doesn't have UI methods.

Try to use playerID, cityID as arguments, then get the city object in the UI context file.
 
It seems that that at least solved the ExposedMember issue (now definitely being called from script to script), but I worry my "context" is still not correct as I am returning the "nil function"
error for anything that I try to run in my UI script that resembles a UI-specific method. I've included a screen shot of my project settings and the modinfo file. I feel like the answer is right in front of me but I'm unsure of how the system detects that it is in "UI context"?

Code:
<?xml version="1.0" encoding="utf-8"?>
<Mod id="99c780bf-f417-490b-a947-34a7b7d75835" version="1">
  <Properties>
    <Name>dataScraper</Name>
    <Description>This is a brief description of the mod.</Description>
    <CustomProperties></CustomProperties>
    <Created>1589611063</Created>
    <Teaser>Module for Civ 6</Teaser>
    <Authors>DARPA</Authors>
    <CompatibleVersions>1.2,2.0</CompatibleVersions>
  </Properties>
  <FrontEndActions />
  <InGameActions>
    <AddGameplayScripts id="gamePlayBackend">
      <File>gamePlayBackend.lua</File>
    </AddGameplayScripts>
    <AddUserInterfaces id="UIFront">
      <File priority="1">UIHelper.xml</File>
      <File priority="-1">UIHelper.lua</File>
    </AddUserInterfaces>
  </InGameActions>
  <Files>
    <File>gamePlayBackend.lua</File>
    <File>UIHelper.lua</File>
    <File>UIHelper.xml</File>
  </Files>
</Mod>

Thanks for your help so much.
 

Attachments

  • UI.PNG
    UI.PNG
    37.8 KB · Views: 53
  • backendOnGamePlay.PNG
    backendOnGamePlay.PNG
    42.8 KB · Views: 43
Updated with complete code in zip, if possible to get a second set of eyes on it just to make sure the general setup is correct.
 

Attachments

  • mod_test.zip
    1.9 KB · Views: 62
Last edited:
you only need to reference the xml file in the <AddUserInterfaces id="UIFront"> section

what's the line of the error ?
 
Top Bottom