Jump to content
cybercoco

Take an array through a function [easy ?]

Recommended Posts

    _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
    _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

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

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
_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

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

 
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

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....

  • Like 1

Share this post


Link to post
Share on other sites

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
_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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×