The array returned by the attachedObjects command contains null objects (objNull) if attached objects were deleted before being detached using the detach command. This is not the behaviour one would expect from this command - the command should not return any null objects.
Description
Details
- Severity
- Minor
- Resolution
- Open
- Reproducibility
- Always
- Operating System
- Windows 10 x64
- Category
- Scripting
- Create a new mission in VR world
- Place a player unit
- Play the mission in SP
- Open debug console and execute the following code:
a = createVehicle ["B_Truck_01_mover_F", [0, 0, 0], [], 0, "NONE"]; b = createVehicle ["B_Truck_01_mover_F", [0, 100, 0], [], 0, "NONE"]; systemChat format ["Before Attach: %1", attachedObjects a]; b attachTo [a]; systemChat format ["After Attach: %1", attachedObjects a]; 0 spawn { sleep 0.1; deleteVehicle b; sleep 0.1; systemChat format ["After Delete: %1", attachedObjects a]; };
- Observe the chat to see the unexpected behaviour.
Chat Output:
Before Attach: [] After Attach: [<not-null object>] After Delete: [<NULL-object>]
To see the correct behaviour, execute the following code (difference from above is that this contains a detach before the deletion):
a = createVehicle ["B_Truck_01_mover_F", [0, 0, 0], [], 0, "NONE"]; b = createVehicle ["B_Truck_01_mover_F", [0, 100, 0], [], 0, "NONE"]; systemChat format ["Before Attach: %1", attachedObjects a]; b attachTo [a]; systemChat format ["After Attach: %1", attachedObjects a]; 0 spawn { sleep 0.1; detach b; deleteVehicle b; sleep 0.1; systemChat format ["After Delete: %1", attachedObjects a]; };
Event Timeline
That is true, however, to me the name attachedObjects implies "return a list of currently attached objects to the given object". An object that doesn't "exist" anymore, can't be attached to the object (or anything).
By your logic the variable that contained object should become nil and not objNull when object is deleted. This is not how it works. You havent detached object so it is considered attached and returned in the array. detach object before you delete it, you are the designer
I fail to see how my comment implies that variables referencing the deleted object should become nil.
I understand your side of the discussion, that because the object was not explicitly detached, it is still considered attached. However, consider this similar situation for Vehicle in Vehicle Transport:
a = createVehicle ["B_Truck_01_flatbed_F", [0, 0, 0], [], 0, "NONE"]; b = createVehicle ["B_MRAP_01_F", [0, 100, 0], [], 0, "NONE"]; systemChat format ["Before setting as cargo: %1", getVehicleCargo a]; a setVehicleCargo b; systemChat format ["After setting as cargo: %1", getVehicleCargo a]; 0 spawn { sleep 0.1; deleteVehicle b; sleep 0.1; systemChat format ["After deleting: %1", getVehicleCargo a]; };
The above code prints out the following in the chat:
Before setting as cargo: [] After setting as cargo: [<not-null object b>] After deleting: []
The above code does not explicitly set the cargo object as not cargo before deletion using objNull setVehicleCargo b, however, it is not considered to be still set as cargo after deletion. I believe that these situations are very similar and for consistency, one should be changed.
I do not see any reasonable purpose for the array returned by attachedObjects to contain objNulls.
Also, it this behaviour is not changed, BIS_fnc_arsenal should be fixed then because every usage of Virtual Arsenal adds a objNull to the array returned by attachedObjects for the unit.
Ok makes sense, ropeAttachedObjects also removes null objects, lets see what we can do