MyopicCat
Chieftain
- Joined
- Jan 6, 2014
- Messages
- 73
Thanks a lot for the detailed answers LeeS! But if GetCulturalProgress() exists in this context then I have no idea what my problem actually is. This is the error message I'm getting:
And this is my Lua code: (line 37 is the line with GetCulturalProgress)
I know that the playerCivics variable isn't nil since it returns correct answers for the turns/yield/cost variables. So I assumed that GetCulturalProgress() wasn't defined here. But if it's not that, then what does the error mean?
BTW, my mod is loaded in-game using the Additional Content menu.
Code:
Runtime Error: C:/Users/me/Documents/My Games/Sid Meier's Civilization VI/Mods/Myopic test mod/GetResearch.lua:37: function expected instead of nil
stack traceback:
C:/Users/me/Documents/My Games/Sid Meier's Civilization VI/Mods/Myopic test mod/GetResearch.lua:37: in function 'OnTurnBegin'
[C]: in function 'func'
[C]: in function '(anonymous)'
And this is my Lua code: (line 37 is the line with GetCulturalProgress)
Code:
function OnTurnBegin(...)
local args = {...};
if args[1] > 0 then
return;
end
print("TESTMOD: TurnBegin event");
local localPlayer = Players[Game.GetLocalPlayer()];
if (localPlayer == nil) then
return;
end
local playerTechs = localPlayer:GetTechs();
local currentTechID :number = playerTechs:GetResearchingTech();
if currentTechID >= 0 then
local progress :number = playerTechs:GetResearchProgress(currentTechID);
local cost :number = playerTechs:GetResearchCost(currentTechID);
print("TESTMOD: Research progress "..progress/cost);
else
print("TESTMOD: No tech being researched");
end
local playerCivics = localPlayer:GetCulture();
local currentCivicID :number = playerCivics:GetProgressingCivic();
print("TESTMOD: " .. currentCivicID)
if currentCivicID >= 0 then
local turns :number = playerCivics:GetTurnsLeftOnCurrentCivic(currentCivicID);
local yield :number = playerCivics:GetCultureYield(currentCivicID);
local cost :number = playerCivics:GetCultureCost(currentCivicID);
print("TESTMOD: turns "..turns .. " yield " ..yield);
print("TESTMOD: Civics progress ".. 1-yield*turns/cost);
local progress :number = playerCivics:GetCulturalProgress(currentCivicID);
print("TESTMOD: Civics absolute progress ".. progress);
else
print("TESTMOD: No civics being researched");
end
print("TESTMOD: end of function");
end
Events.PlayerTurnActivated.Add( OnTurnBegin )
BTW, my mod is loaded in-game using the Additional Content menu.