-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error when full share transfers units to a dead player #6432
Conversation
lua/aibrain.lua
Outdated
@@ -495,7 +495,7 @@ AIBrain = Class(FactoryManagerBrainComponent, StatManagerBrainComponent, JammerM | |||
units = self:GetListOfUnits(categories.ALLUNITS - categories.WALL - categories.COMMAND, false) | |||
end | |||
if units and not table.empty(units) then | |||
local givenUnitCount = table.getn(TransferUnitsOwnership(units, brain.index)) | |||
local givenUnitCount = table.getn(TransferUnitsOwnership(units, brain.index) or {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overthinking. Put function result into a variable and check against nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, also I can use next()
instead of table.getn > 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also bad idea. table.empty
would be more understandable.
I doublt |
It does accept nil: Lines 59 to 62 in 2d1e06a
|
https://github.com/FAForever/fa/blob/develop/lua/simInit.lua#L25 |
Console command: SimLua
LOG('"table.empty":', table.empty, '"table.empty(nil)"', table.empty(nil))
LOG('"table.empty2":', table.empty2, '"table.empty2(nil)"', table.empty2(nil)) Output:
|
Also |
It is seems like a bug. Currently pending. |
Issue
Reported on Discord. Replay 23190625.
The game tried to transfer units to a defeated player which causes the
TransferUnitsOwnership
function to return nil, andTransferUnitsToBrain
didn't handle this case before putting the results intotable.getn
.Description of the proposed changes
Add a guard so that it puts an empty table into
getn
if the result is nil.Testing done on the proposed changes
Running the replay again with the changes properly transfers the units after the player dies.
To run the replay with changes from your local repo, load the replay from the FAF client to unpack it, and then run the console command:
Checklist
TransferUnitsOwnership
function has a proper return value ofUnit[]?