When you provide nil in setUnitLoadout array for backpack slot, the engine still deletes and re-creates old backpack. This is an issue because assemble-able backpacks hold link to vehicles they assemble and this means the vehicle will be created anew and all its previous states like damage, ammo, variables will be lost.
Description
Description
Details
Details
- Severity
- None
- Resolution
- Open
- Reproducibility
- N/A
- Operating System
- Windows 10 x64
- Category
- Scripting
Steps To Reproduce
- Start playing
- Execute in debug console:
if(backpack player == "") then {player addBackpack "Bag_Base"}; oldBP = backpackContainer player; systemChat str ["oldBP", oldBP]; l = getUnitLoadout player; l set [5, nil]; player setUnitLoadout l; newBP = backpackContainer player; systemChat str ["newBP", newBP]; systemChat str ["newBP == oldBP", newBP == oldBP];
- Observer newBP == oldBP being false
Event Timeline
Comment Actions
Would you expect the same to happen when doing this
l = getUnitLoadout player; player setUnitLoadout l;
When not setting it to nil, but just leaving it unchanged. Would you also expect it to keep the game backpack?
The difference of "keep same backpack" and "re-apply same type of backpack with same contents"
Currently the code doesn't know that it was nil.
It essentially calls getUnitLoadout, and replaces every nil with data from that.
Easy fix, if backpack is same classname, just keep it. But that has some potential for backwards compat nightmares.
Less-easy fix, store a flag and remember if it was "nil", and only then keep it.
Comment Actions
I think checking if input backpack was nil as a flag to keep old backpack would be the best solution here. Best backwards compatibility-wise.