Sid Meier's Civilization VI

Sid Meier's Civilization VI

Gift It To Me
sdgabai 1 Jun, 2019 @ 11:11pm
lua.log error report : Index a nil value
Runtime Error: 1683750352\Scripts\GiftItToMeNow.lua:627: attempt to index a nil value
stack traceback:
1683750352\Scripts\GiftItToMeNow.lua:627: in function 'OnUnitFormCorps'
1683750352\Scripts\GiftItToMeNow.lua:636: in function 'OnUnitFormArmy'
[C]: in function 'func'
[C]: in function '(anonymous)'

Folder:
1683750352\Scripts\

File:
GiftItToMeNow.lua

Function:
OnUnitFormCorps

Line:
627

Code:
local unitType = GameInfo.Units[unit:GetType()].UnitType;

Full Context:
-- Hook into corp-formation
function OnUnitFormCorps(playerId, unitId)
-- Logging
WriteToLog("OnUnitFormCorps")
WriteToLog(playerId)
WriteToLog(unitId)

-- Fetch player data
local player = Players[playerId];
local unit = player:GetUnits():FindID(unitId);
local unitType = GameInfo.Units[unit:GetType()].UnitType;

-- Memorize freed resource
XP2FreeResourceConsumption(playerId, unitType);
end

The code should do some error checking for nil condition before indexing and handle it
Since I'm not familiar with the context of the consequences of a nil condition,
I don't know what to suggest exactly.
Also, I am a dinosaur and don't know serious modern coding skills.

if unit:GetType() ~= nil then
local unitType = GameInfo.Units[unit:GetType()].UnitType;
end
Last edited by sdgabai; 24 Jun, 2019 @ 10:25pm
< >
Showing 1-2 of 2 comments
sdgabai 1 Jun, 2019 @ 11:13pm 
good luck, and thank you for a wonderful mod and your contributions to the community
Fampat  [developer] 15 May, 2020 @ 11:48pm 
Thank you for pointing this out, because the moid will get active again, ill have this sorted!

Update:
I had a look at this, the only case i can image this happened is that there is a unit on the field which has no type within the game-database (what is this error is telling us).

I guess therefor this has happened because of a incompatibility with an other mod which is implementing new units (not properly?).

Nonetheless i added a check and a log to find out which units this could be, if you update this mod and play again and do get a error-log, please let me know what it tells... if you play this game anymore, its been a while since you wrote this haha
Last edited by Fampat; 16 May, 2020 @ 12:24am
< >
Showing 1-2 of 2 comments
Per page: 1530 50