OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Terox on 01 Oct 2009, 20:26:02
-
I am trying to add a condition to an addaction that monitors _x, which in this case is a BIS artillery module
the condition is [_x] call BIS_ARTY_F_Available
which returns a boolean
when testing, this condition is known to be true, but the addaction will not display in the user action list.
When I remove this condition, the addaction displays correctly.
Thus the rest of the code is correct and the implementation of the _x condition is not seen as true
Any ideas how to implement this condition correctly ?
_object = _this select 0;
_caller = _this select 1;
_myBatterys = [];
_id = 0;
_title = "";
{if(side _caller == side (_x call BIS_ARTY_F_BatteryLead))then
{
_myBatterys = _myBatterys + [_x];
_title = format [" Select %1", _x];
_batteryID = call compile format ["Tx_batteryID_%1",_id];
_id = _object addaction [_title, Tx_ActionPath + "Arty\Arty01_selectBattery.sqf", _x , -20 , false , false , "" , "( Tx_DisplayActions) && (alive _target) && (_target getvariable ""Tx_ArtyStage"" == 1)&&([_x] call BIS_ARTY_F_Available)"];
_id = _id + 1;
}
}foreach BIS_ARTY_BATTERYCAT;
-
Use a simple for-iteration and save the iteration variable (mostly _i).
So you can use BIS_ARTY_BATTERYCAT select ... to get the battery.
And be aware that "_i" will be "_i" and not "0" or another number. Use str _i which will return "0".
-
The addAction is probably not parsed during creation, so _x will remain _x, which is meaningless outside the scope of the forEach loop.
You probably need to use call compile format on the line that creates the action.
-
Thanks for the input guys
working solution, thanks to killswitch... and input from you guys
_object = _this select 0;
_caller = _this select 1;
_title = "";
_c=count BIS_ARTY_BATTERYCAT;
if (_c>0) then
{
for [{_i=0}, {_i<_c}, {_i=_i+1}] do
{
_battery = BIS_ARTY_BATTERYCAT select _i;
if (side _caller == side(_battery call BIS_ARTY_F_BatteryLead)) then
{
_title = format [" Select %1", _battery];
_condition = format ["Tx_DisplayActions&&(alive _target)&&(_target getVariable'Tx_ArtyStage'==1)&&([BIS_ARTY_BATTERYCAT select %1] call BIS_ARTY_F_Available)", _i];
_actionID = _object addAction [_title, Tx_ActionPath + "Arty\Arty01_selectBattery.sqf", _battery , -20 , false , false , "" , _condition];
_ArtyActions = _object getVariable "Tx_ArtyActions";
_object setVariable ["Tx_ArtyActions",(_ArtyActions + [_actionID])];
};
};
};