Jump to content
S3LMON

I want to be able to run a function on all elements in an array!

Recommended Posts

Good morning! 🙂

 

I want to be able to run a function on all elements in an array.

Let me show you the code first.


(I removed the part I thought was useless for easier viewing because it was too long)

// Fnc.sqf


Fnc_2 = {
	Unit_2 = _this select 0;

	/*
	//I just want to lie on a warm bed...

	Execute the visible effect of the function!

	*/
};

Fnc_1 = {	
	Unit_1 = _this select 0;	
	while {alive Unit} do
	{
		/*
		//Scripting is very difficult...

		It repeats until the "conditions" under which Fnc_2 can be executed are satisfied!

		*/

		if ("Condition_1") exitwith {		
			[Unit_1] call Fnc_2;
		};
		if ("Condition_2") exitwith {
			[Unit_1] call Fnc_2;
		};
		if ("Condition_3") exitwith {
			[Unit_1] call Fnc_2;
		};
	};
};

0 = [] spawn {
  	while {true} do {   		 
		Unit_Array = vehicles select {isNil {_x getVariable "Val" }};
		{
			if (isNil {_x getVariable "Val"}) then {	
				_x setVariable ["Val",TRUE];	
				[_x] spawn Fnc_1;
			};
		} forEach Unit_Array;
	};
};    	

The problem I am having with the above code is:

 

If there is [Unit1, Unit2] in Unit_Array, I manipulated Unit1 so that Fnc_2 can be executed. Fortunately, Unit1 ran Fnc_2, but Unit2, which didn't transform anything, also ran Fnc_2.

 

What's the problem?

I've been wasting my time for almost 2 weeks on this issue...

 

Thank you for reading! 🙂

 

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

×