Issetea
Jun 3 2009, 11:59
While still converting some ArmA1 scripts to ArmA2 we've encountered a ?bug? in the exitWith command. Can someone tell me whether I'm using it wrong or it's a real ArmA bug please?
Here is a small example of the exitWith in ArmA2 (The function doesn't make much sense but it's just an example):
// Searches given Parameter in the array "_arr" and returns the array. In this example it returns: [1] for parameter: 1
INV_getitemArray = {
private ["_c", "_Fobjarray", "_arr"];
_Fobjarray = [];
_arr = [[1]];
for [{_c=0}, {_c < (count _arr)}, {_c=_c+1}] do {
if (((_arr select _c) select 0) == _this) exitWith { _Fobjarray = _arr select _c; /* true */ };
};
hint "Still returns the array after exit.";
_Fobjarray
};
INV_getitemName = { ((_this call INV_getitemArray) select 0) };
_amount = 10;
hint format["Test-1: %1, %2", _amount, (1 call INV_getitemName)];
hint format["Test-2: %1, %2", _amount, 1];
Output:
"Still returns the array after exit."
"Test-1: <null>, 1" <- Amount should be 10, instead, it's the reutned value of the exitWith block.
"Test-2: 10, 1"
Notes
Replacing "exixtWith" with "then" fixes the problem. If we return true (At the comment above), the _amount variable in the first output will be "true" as well, in the second, it will be 10 again.
Here is a small example of the exitWith in ArmA2 (The function doesn't make much sense but it's just an example):
// Searches given Parameter in the array "_arr" and returns the array. In this example it returns: [1] for parameter: 1
INV_getitemArray = {
private ["_c", "_Fobjarray", "_arr"];
_Fobjarray = [];
_arr = [[1]];
for [{_c=0}, {_c < (count _arr)}, {_c=_c+1}] do {
if (((_arr select _c) select 0) == _this) exitWith { _Fobjarray = _arr select _c; /* true */ };
};
hint "Still returns the array after exit.";
_Fobjarray
};
INV_getitemName = { ((_this call INV_getitemArray) select 0) };
_amount = 10;
hint format["Test-1: %1, %2", _amount, (1 call INV_getitemName)];
hint format["Test-2: %1, %2", _amount, 1];
Output:
"Still returns the array after exit."
"Test-1: <null>, 1" <- Amount should be 10, instead, it's the reutned value of the exitWith block.
"Test-2: 10, 1"
Notes
Replacing "exixtWith" with "then" fixes the problem. If we return true (At the comment above), the _amount variable in the first output will be "true" as well, in the second, it will be 10 again.