Jump to content
Sign in to follow this  
wok

function returning "any"

Recommended Posts

I am doing a stances indicator, my .sqf file look kinda like this:

if (isDedicated) exitWith {};

waitUntil {!isNull player && player == player};

_position = call getStance;
hint format ['%1 - %2 - %3',_position select 0, _position select 1, _position select 2];

getStance =
{
_animation = animationState player;
_stance = stance player;
_vPosition = "MIDDLE";
_hPosition = "MIDDLE";

if ( [_animation, "down"] call findStr ) then
{
	_vPosition = "DOWN";
};

if ( [_animation, "up"] call findStr ) then
{
	_vPosition = "UP";
};

if ( [_animation, "left"] call findStr ) then
{
	_hPosition = "LEFT";
};

if ( [_animation, "right"] call findStr ) then
{
	_hPosition = "RIGHT";
};

[_stance, _vPosition, _hPosition]
};

findStr =
{
_str1 = toArray(_this select 0);
_str2 = toArray(_this select 1);
_substr = [];
_result = false;

for "_i" from 0 to ((count _str2) - 1) do 
{
	_substr set [_i, _str1 select (count _str1 - count _str2 + _i)];
};

if([_substr, _str2] call BIS_fnc_areEqual) then 
{
	_result = true;
};

_result
};

In the init.sqf file I have:

_null = [] execvm "myFile.sqf";

The hint shows "any - any - any", if I call the function inside an event handler like AnimDone, then the hint shows the correct values.

Does anyone knows why the function returns "any" and how could I fix it?

I suspect I need to add something else to the top waitUntil, but im not sure what.

Share this post


Link to post
Share on other sites

Hello! I was looking at it and was able to get the first value to say the correct value ( http://2.ii.gl/GhH2E.png ) but the last two say MIDDLE, not sure if that is correct! but this is what i did, just moved _position and the hint to the bottom of the script

if (isDedicated) exitWith {};

waitUntil {!isNull player && player == player};




getStance =
{
   _animation = animationState player;
   _stance = stance player;
   _vPosition = "MIDDLE";
   _hPosition = "MIDDLE";


   if ( [_animation, "down"] call findStr ) then
   {
       _vPosition = "DOWN";
   };

   if ( [_animation, "up"] call findStr ) then
   {
       _vPosition = "UP";
   };

   if ( [_animation, "left"] call findStr ) then
   {
       _hPosition = "LEFT";
   };

   if ( [_animation, "right"] call findStr ) then
   {
       _hPosition = "RIGHT";
   };

   [_stance, _vPosition, _hPosition]
};


findStr =
{
   _str1 = toArray(_this select 0);
   _str2 = toArray(_this select 1);
   _substr = [];
   _result = false;

   for "_i" from 0 to ((count _str2) - 1) do 
   {
       _substr set [_i, _str1 select (count _str1 - count _str2 + _i)];
   };

   if([_substr, _str2] call BIS_fnc_areEqual) then 
   {
       _result = true;
   };

   _result;
};    


_position = call getStance;
hint format ['%1 - %2 - %3',_position select 0, _position select 1, _position select 2];


Hope this helps! :)

Share this post


Link to post
Share on other sites

what toxic did, you need to define function first then call it not call it then define it.

Share this post


Link to post
Share on other sites

Thank you toxic and killzone, I come from other programming languages, but I should have though about this :P. Thank you very much..

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
Sign in to follow this  

×