slothstronaut 10 Posted June 12, 2016 Hey guys, I'm storing an array of actions and objects, and rather than have to write a handler for each equipment type as it comes through, I'd like to be able to do something a little more generic. Here's a small example of what I'm trying to do (please note, this is not production ready, just a test): _command = "addGoggles=G_Aviator"; _split = _command splitString "="; _unit = player; _function = _split select 0; _object = _split select 1; >> insert part I don't know how to do but something like _unit _function _object or in pseudo "for this unit, call this function, with this argument" I've looked into call and it doesn't seem to work with having an argument on the left hand side (such as player addGoggles "G_Aviator"; for example). I can get it to work if I write a helper function, which looks like this: kitAddGoggles = { params ["_unit", "_object"]; _unit addGoggles _object; }; _command = "kitAddGoggles=G_Aviator"; _split = _command splitString "="; _unit = player; _object = _split select 1; _function = _split select 0; _params = [_unit, _object]; _params call call compile _function; But I'd prefer to not have to do a helper for every equipment type. Anyone have anything they can suggest, or even if this is possible? Cheers! Share this post Link to post Share on other sites
kylania 568 Posted June 12, 2016 You've basically got it right. // Function declared in init.sqf or via the whole CfgFunctions thing*. fn_kitAddGoggles = { params ["_unit", "_object"]; _unit addGoggles _object; }; // Call in a script somewhere to give player a pair of G_Aviator goggles. [player, "G_Aviator"] call fn_kitAddGoggles; CfgFunctions information. Share this post Link to post Share on other sites
slothstronaut 10 Posted June 12, 2016 I was hoping to avoid having a helper function like fn_kitAddGoggles and just call addGoggles directly, but if this is the only way, it's not so bad. Thanks for the reply! Share this post Link to post Share on other sites
kylania 568 Posted June 12, 2016 You can absolutely just do: player addGoggles "G_Aviator"; The function is so that you can give any unit any goggle without having to type out addGoggles a zillion times. Share this post Link to post Share on other sites
slothstronaut 10 Posted June 12, 2016 Oh, I know I can call it explicitly, but I was hoping to call it by reference, so, something like: _unit = player; _function = "addGoggles"; _object = "G_Aviator"; _unit _function _object; Share this post Link to post Share on other sites
serena 151 Posted June 12, 2016 call compile ([_unit, _function, str _object] joinString " "); //Result: call compile "player addGoggles ""G_Aviator""" //Result: call {player addGoggles "G_Aviator"} Final solution: private _str = "player addGoggles ""G_Aviator"""; private _dta = _str splitString " "; call compile (_dta joinString " "); Share this post Link to post Share on other sites
slothstronaut 10 Posted June 12, 2016 That doesn't seem to work, unfortunately. Complains that there's a missing semi-colon, no matter how I rearrange things. Share this post Link to post Share on other sites
serena 151 Posted June 12, 2016 That doesn't seem to work, unfortunately. Complains that there's a missing semi-colon, no matter how I rearrange things. Just tested, both variants works fine for me Share this post Link to post Share on other sites
slothstronaut 10 Posted June 12, 2016 Apologies, I didn't see your update. That definitely did work. Fantastic! Thank you very much! Share this post Link to post Share on other sites
das attorney 858 Posted June 12, 2016 Final solution: That sounds a bit extreme.. Share this post Link to post Share on other sites
serena 151 Posted June 12, 2016 That sounds a bit extreme.. I agree. And even more, it sounds stupid. I apologize to all whom it will bring inconvenience Share this post Link to post Share on other sites
das attorney 858 Posted June 12, 2016 Don't worry - I wasn't having a go, it just looked funny. Share this post Link to post Share on other sites