Jump to content
Sign in to follow this  
SEKO72

Working with Arrays to optimize the script

Recommended Posts

Hello folks,

 

I ran into another scripting-wall and can't figure it out or find any fitting information on the wiki. 

I am scripting a hostage rescue scenario in wich the players mission is to "clear" a buildung and capture or kill any Tangos while rescuing as many hostages as they can. I thought that a smart way to get started with this would be (once againt) an EventHandler in the init.sqf file that fires when a Tango gets killed. I have 25 enemies in the building and placed them in an Array to keep my codelines short. Now I want the EH to check if the killed nps is in this Array...and it just won*t work.

 

So my Code looks like this

 

 

this addEventHandler ["Killed", 

{hint "test 1 2 3";}

]; forEach in _myArray;

 

Cheers

SEKO

 

Share this post


Link to post
Share on other sites

Any command requires a specific syntax to execute properly. In the case of forEach, it is:

{<code>} forEach [<array>]

forEach also uses the magic variable _x to iterate the code through the array.
 

Your snippet should then look more like this:

{_x addEventHandler ["Killed", 
    {hint "test 1 2 3";}
]} forEach _myArray;

 

  • Like 2

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  

×