Jump to content
Sign in to follow this  
jphilapy

Something different about foreach

Recommended Posts

For some reason the following which works good in OFP is not working in arma:

gogs = "NVGoggles";

_units3 = units east1;

"_x addweapon gogs" foreach _units3;

I get the error message:

'"_x addweapon gogs" |#| foreach _units3;'

Error foreach: type string, expected code

What should I be doing differently?

Thanks,

Jeff

Share this post


Link to post
Share on other sites

Code requires curled braces:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addweapon gogs} foreach _units3;

Share this post


Link to post
Share on other sites

I can't test right now if it makes a difference but try brackets instead of the quotes, thats how i do foreach statements:

{_x addweapon gogs} foreach _units3;

and from the Biki:

{

STATEMENT;

...

}

forEach ARRAY;

Hope that helps,

Charon

Share this post


Link to post
Share on other sites
I can't test right now if it makes a difference but try brackets instead of the quotes, thats how i do foreach statements:

{_x addweapon gogs} foreach _units3;

and from the Biki:

{

   STATEMENT;

   ...

}

forEach ARRAY;

Hope that helps,

Charon

Hi guys, thanks for the help. Yes I tried the brackets and it works fine. However now this statement with brackets is broken, but with quotes it throws no error:

unitpos = "UP";

{_x setunitpos unitpos} foreach _units3; Throws the same error that I quoted in my previous post

"_x setunitpos unitpos" foreach _units3; Doesn't throw any error.

Maybe foreach is inconsistent?

Jeff

Share this post


Link to post
Share on other sites

nevermind, i think i solved my own problem. It appears that the variable i am using, unitpos, is now a command in arma.

Fixed.

Jeff

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  

×