I am currently writing a script which creates addaction items for the player based on nearby vehicles.
I get the _vehiclesnear array, step through it in a foreach loop, filter out 'vehicles' I am not interested in and then do an add action for each of the remaining vehicles.
The text for the Addaction includes the vehicle type and works fine for each addaction. The problem is the passed variable. I wish to add an action with the object _x as a parameter for each value of _x at the time of the add action.
What I am getting is the last value of _x after the foreach loop has completed is being passed when any of the actions added are selected.
i.e. (code is not syntax correct as it is from my memory but you should get the general idea)
Question
RimBlock
Hi,
I am currently writing a script which creates addaction items for the player based on nearby vehicles.
I get the _vehiclesnear array, step through it in a foreach loop, filter out 'vehicles' I am not interested in and then do an add action for each of the remaining vehicles.
The text for the Addaction includes the vehicle type and works fine for each addaction. The problem is the passed variable. I wish to add an action with the object _x as a parameter for each value of _x at the time of the add action.
What I am getting is the last value of _x after the foreach loop has completed is being passed when any of the actions added are selected.
i.e. (code is not syntax correct as it is from my memory but you should get the general idea)
_vehiclesnear = ["Soldier","SUV","heli", "Player"];
_playerlist = ["Soldier","Player"];
{
if !(_x in _playerlist) then {
_vehicleType = typeof (_vehicleType);
_actionText = format["Vechicle is : %1", _x];
actionHandle = player addaction _actiontext, [_x], "script.sqf";
};
}foreach vehiclesnear;
The output action would be something like
"Vechicle is : SUV"
"Vechicle is : heli"
When any option is selected, "Player" will be sent to script.sqf as it was the last value _x contained when the foreach loop finished.
Any suggestions of how I can get the addaction to send the correct value to the script (i.e. the value of _x when the addaction was run) ?.
Thanks.
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now