cybercoco 16 Posted January 17, 2016 _fnc_Hp = { _this select _i from 0 to 2 do { round (((_this * -100) + 100)); }; }; _all = [_won getHit "motor",_won getHit "palivo",_won getHit "karoserie"]; hint format ["%1", _all]; sleep 2; hint format ["%1", _all call _fnc_Hp]; How do I take the array _all containing [_won getHit "motor",_won getHit "palivo",_won getHit "karoserie"] through the function _fnc_Hp Share this post Link to post Share on other sites
davidoss 550 Posted January 17, 2016 _fnc_Hp = { params ["_array", "_return", "_i"]; _return = []; _array select _i from 0 to 2 do { round (((_array * -100) + 100)); _return set [_i, _array]; }; _return; }; _all = [_won getHit "motor",_won getHit "palivo",_won getHit "karoserie"]; _alldamage = [_all] call _fnc_Hp; Try this is that what you need? Share this post Link to post Share on other sites
cybercoco 16 Posted January 17, 2016 Thanks Davidoss, however the code doesn't work yet : _all outputs [0,0,0] _alldamage outputs [] _fnc_Hp = { params ["_array", "_return", "_i"]; _return = []; _array select _i from 0 to 2 do { round (((_array * -100) + 100)); _return set [_i, _array]; }; _return; }; _all = [_won getHit "motor",_won getHit "palivo",_won getHit "karoserie"]; _alldamage = [_all] call _fnc_Hp; // debugg hint format ["%1", _all]; sleep 2; hint format ["%1", _alldamage]; Share this post Link to post Share on other sites
davidoss 550 Posted January 17, 2016 You need to define _won if you not did it Share this post Link to post Share on other sites
cybercoco 16 Posted January 17, 2016 You need to define _won if you not did it It is already defined as the vehicle name... Share this post Link to post Share on other sites
cybercoco 16 Posted January 17, 2016 _fnc_Hp = { params ["_array", "_return", "_i"]; _return = []; _array select _i from 0 to 2 do { round (((_array * -100) + 100)); _return set [_i, _array]; }; _return; }; _all = [0,0,0]; _alldamage = [_all] call _fnc_Hp; // tested _all and [_all] and [0,0,0] hint format ["%1", _alldamage]; Tried with an array of [0,0,0], still doesn't work... Share this post Link to post Share on other sites
davidoss 550 Posted January 17, 2016 For some reason its not working for me too. _fnc_Hp = { params ["_array", "_return", "_i", "_index"]; _return = []; for _i from 0 to floor (count _array) do { _index = round ((_array select _i)* -100) + 100; _return set [_i, _index]; }; _return; }; _index = 48 for _all select 0 where _all = [0.515342,0.515342,0.515342]; _return outputs [] I am afraid we need some smarter heads here... Share this post Link to post Share on other sites
Greenfist 1863 Posted January 17, 2016 You're confusing params with private.And floor (count _array) would return a too high index. You should usually use (count _array -1). _fnc_Hp = { private ["_return","_array"]; _array = _this select 0; _return = []; { _return pushBack (round ((_x * -100) + 100)) } foreach _array; _return; }; _alldamage = [_all] call _fnc_Hp; The next game update will introduce a new command which reduces this to: _fnc_Hp = { (_this select 0) apply {round ((_x * -100) + 100)} }; Share this post Link to post Share on other sites
davidoss 550 Posted January 17, 2016 I am not confusing params and private you can merge those together like Killzone Kid says on params wiki site at bottom. Share this post Link to post Share on other sites
Greenfist 1863 Posted January 17, 2016 I am not confusing params and private you can merge those together like Killzone Kid says on params wiki site at bottom. Huh, I did not know that. :) Share this post Link to post Share on other sites
killzone_kid 1326 Posted January 17, 2016 For some reason its not working for me too. _fnc_Hp = { params ["_array", "_return", "_i", "_index"]; _return = []; for _i from 0 to floor (count _array) do { _index = round ((_array select _i)* -100) + 100; _return set [_i, _index]; }; _return; }; _index = 48 for _all select 0 where _all = [0.515342,0.515342,0.515342]; _return outputs [] I am afraid we need some smarter heads here... The syntax to "for" loop above should be for <string> from.... 1 Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted January 17, 2016 For some reason its not working for me too. _fnc_Hp = { params ["_array", "_return", "_i", "_index"]; _return = []; for _i from 0 to floor (count _array) do { _index = round ((_array select _i)* -100) + 100; _return set [_i, _index]; }; _return; }; _index = 48 for _all select 0 where _all = [0.515342,0.515342,0.515342]; _return outputs [] I am afraid we need some smarter heads here... In addition to what KK said, floor will not reduce an integer number by 1, which you are trying to do in floor (count _array). That means, you're still gonna select a nil value behind the last value of _array which will result in an error. And why are you not doing your stuff in a forEach loop anyway? _all = [0.515342,0.515342,0.515342]; { _all set [_forEachIndex, floor (_x * 100) / 100]; } forEach _all; hintSilent str _all; //[0.51,0.51,0.51] Share this post Link to post Share on other sites
davidoss 550 Posted January 17, 2016 As easy as said...Thanks, learn much about Share this post Link to post Share on other sites
cybercoco 16 Posted January 22, 2016 _fnc_Hp = { private ["_return","_array"]; _array = _this select 0; _return = []; { _return pushBack (round ((_x * -100) + 100)) } foreach _array; _return; }; _alldamage = [_all] call _fnc_Hp; I get how it's working now, thank you Greenfist. The next game update will introduce a new command which reduces this to: _fnc_Hp = { (_this select 0) apply {round ((_x * -100) + 100)} }; That will be very handy indeed ! In addition to what KK said, floor will not reduce an integer number by 1, which you are trying to do in floor (count _array). That means, you're still gonna select a nil value behind the last value of _array which will result in an error. And why are you not doing your stuff in a forEach loop anyway? _all = [0.515342,0.515342,0.515342]; { _all set [_forEachIndex, floor (_x * 100) / 100]; } forEach _all; hintSilent str _all; //[0.51,0.51,0.51] Thanks for the solution Heeeere's johnny!, it's a quick way to solve the problem. Share this post Link to post Share on other sites