Chrisy15
Flower, Beautiful
- Joined
- Jul 9, 2015
- Messages
- 2,137
Hello Lua modders!
I'm here because of a problem to do with trade routes.
I'm trying to give Golden Age points to the player based off of the gold they are receiving from their International Trade Routes.
I've been basing it off of LeeS's code, but I've run into a problem.
These are my two functions:
However, for some reason, tPlayerTradeRoutes is a nil value:
The value remains nil regardless of whether there are any trade routes or not; the DTP function doesn't fire if there aren't any trade routes, but it does still remain nil.
Any explanation?
I'm here because of a problem to do with trade routes.
I'm trying to give Golden Age points to the player based off of the gold they are receiving from their International Trade Routes.
I've been basing it off of LeeS's code, but I've run into a problem.
These are my two functions:
Code:
function C15_SKorea_DTP_GAPfromTradeRoutes(iPlayer, pCity, tPlayerTradeRoutes)
local iTradeRouteGoldTotal = 0
[COLOR="Red"]for i = 1, #tPlayerTradeRoutes do[/COLOR] --Error is refering to this line - forgot that you wouldn't be able to see that!
if (tPlayerTradeRoutes[i]["FromID"] == iPlayer) and not (tPlayerTradeRoutes[i]["ToID"] == iPlayer) then
if tPlayerTradeRoutes[i]["FromCity"] == pCity then
iTradeRouteGoldTotal = iTradeRouteGoldTotal + tPlayerTradeRoutes[i]["FromGPT"]
end
end
end
return iTradeRouteGoldTotal
end
Code:
function C15_SKorea_GAPfromTradeRoutes(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == civilisationID then
local tPlayerTradeRoutes = pPlayer:GetTradeRoutes()
if #tPlayerTradeRoutes > 0 then
for pCity in pPlayer:Cities() do
C15_SKorea_DTP_GAPfromTradeRoutes(iPlayer, pCity, tPlayerTradeRoutes)
pPlayer:ChangeGoldenAgeProgressMeter(iTradeRouteGoldTotal)
print("GAP added: ", iTradeRouteGoldTotal)
end
end
end
end
if isSKActive then
GameEvents.PlayerDoTurn.Add(C15_SKorea_GAPfromTradeRoutes)
print("GAP From Trade Routes added!")
end
However, for some reason, tPlayerTradeRoutes is a nil value:
Code:
\C15_SKorea_TopPanelSupport.lua:65: attempt to get length of local 'tPlayerTradeRoutes' (a nil value)
The value remains nil regardless of whether there are any trade routes or not; the DTP function doesn't fire if there aren't any trade routes, but it does still remain nil.
Any explanation?