Zegangani
King
- Joined
- Oct 9, 2020
- Messages
- 897
I want to get lua to show the current Production Progress of a Unit (and Building, but didn't try this latter) but I always get a Nil value from this code:
The Nil value error comes from the line: "nProductionProgress : number = pBuildQueue:GetUnitProgress( UnitToBuild );"
(The Code is a little bit messy cause it's just for testing purposes)
I've tryed many things (changed the function's code, the HookEvents...) but I always get the Nil value.
Any Ideas how to get this to work?
Thanks in advance!
Code:
function OnUnitProductionHash(PlayerID, CityID, iProdcutionItemType, unitReference)
local pPlayer = Players[PlayerID];
local pCity = pPlayer:GetCities():FindID(CityID)
if pCity ~= nil then
for row in GameInfo.Units() do
local UnitHash = row.Hash
local UnitTypeInfo = GameInfo.Units[row.UnitType];
local UnitToBuild = row.Index
local UnitName = Locale.Lookup(UnitTypeInfo.Name);
print("Check 1", UnitName, UnitToBuild, UnitHash);
if (UnitTypeInfo ~= nil) then
local pBuildQueue: table = pCity:GetBuildQueue()
local nProductionProgress : number = pBuildQueue:GetUnitProgress( UnitToBuild );
print("Check 2", UnitName, UnitToBuild, UnitHash, nProductionProgress);
end
end
end
end
The Nil value error comes from the line: "nProductionProgress : number = pBuildQueue:GetUnitProgress( UnitToBuild );"
(The Code is a little bit messy cause it's just for testing purposes)
I've tryed many things (changed the function's code, the HookEvents...) but I always get the Nil value.
Any Ideas how to get this to work?
Thanks in advance!
Last edited: