[R&F] Help for function GetTurnsLeft

zhadingping

Chieftain
Joined
Nov 28, 2016
Messages
5
There is a runtime error in the following function:

Can someone tell me why? thanks a lot.


function CheckWonderInBuilding(forHumanPlayer)
local oCity, numWonder
local WonderTable={}
local tplayers = Game.GetPlayers();

numWonder = 0
for i, player in ipairs(tplayers) do
if ( player:IsAlive() and player:IsMajor() and (player:IsHuman()==forHumanPlayer) ) then
local oCity = nil;
local oCities = player:GetCities();
for j, oCity in oCities:Members() do
for row in GameInfo.Buildings() do
--for UI
--if ( row.Hash == oCity:GetBuildQueue():GetCurrentProductionTypeHash() and row.MaxWorldInstances == 1 and row.IsWonder ) then
--for GameplayScripts
if ( row.BuildingType == oCity:GetBuildQueue():CurrentlyBuilding() and row.MaxWorldInstances == 1 and row.IsWonder ) then
local wonderName = row.Name;
--print (row.BuildingType, wonderName);
--print (row.Hash);

---------------------The following line is error

local tempTurns = oCity:GetBuildQueue():GetTurnsLeft(row.Hash);



--print (tempTurns);
if ( WonderTable[wonderName]==nil ) then
WonderTable[wonderName] = {};
WonderTable[wonderName]['Turns']=tempTurns;
WonderTable[wonderName]['CityID']=oCity:GetID();
numWonder = numWonder+1;
else
WonderTable[wonderName]['Turns'] = math.min(tempTurns, WonderTable[wonderName]['Turns']);
WonderTable[wonderName]['CityID']=oCity:GetID();
end
break
end
end
end
end
end

return numWonder, WonderTable

end
 
As I recall City:GetBuildQueue():GetTurnsLeft(BuildingIndexNumber); is not actually implemented on the In-Game context even though it showing as so in Gedemon's spreadsheet, so you always get nil [edit>] function runtime errors.

Also, (player:IsHuman()==forHumanPlayer) would seem to be problematical since IsHuman() is a boolean and would therefore only allow the function to pass that point if you are passing a boolean value for forHumanPlayer
 
Last edited:
As I recall City:GetBuildQueue():GetTurnsLeft(BuildingIndexNumber); is not actually implemented on the In-Game context even though it showing as so in Gedemon's spreadsheet, so you always get nil.

Also, (player:IsHuman()==forHumanPlayer) would seem to be problematical since IsHuman() is a boolean and would therefore only allow the function to pass that point if you are passing a boolean value for forHumanPlayer

Thanks a lot.
 
Top Bottom