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
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