Jump to content
Sign in to follow this  
Rommel

Interesting: FOREACH in FORMAT

Recommended Posts

VARX = format ["%1", {alive _x; _x} foreach allunits];

Returns the last unit in allUnits;

VARX = format ["%1", {alive _x} foreach allunits];

Returns true;

Semi strange behavior, considering:

VARX= {alive _x} foreach allunits

Returns nothing.

Share this post


Link to post
Share on other sites

The third description also returns true or false (VARX) in my test.

All three description returns the value at the tail end variable in {}. The reason which returns a result seems to be consistently satisfactory.

Share this post


Link to post
Share on other sites

Interesting, where did you execute the code? I did mine in triggers, and it would not return anything. I'll give it a shot executing in init.sqf.

edit: Yup, works in init.sqf

Edited by Rommel

Share this post


Link to post
Share on other sites
VARX = format ["%1", {alive _x; _x} foreach allunits];

Returns the last unit in allUnits;

{alive _x; _x} - that last ;_x is returned, and since _x refers to the item passed into the block, this one makes sense.

Why those last two come back different, that's confusing, thought it would've worked anywhere. :confused:

Share this post


Link to post
Share on other sites

Which is what intrigued me, the first two make sense.

Share this post


Link to post
Share on other sites
sleep 1;

VARX= {alive _x} foreach allunits; //The third description.

player sidechat format["%1",VARX];

I think that no results are returned because the assignment expression itself is written to the format command.

In order to display a script error, it is good to carry out -showScriptErrors option use.

@bhaz

"format ["%1", {alive _x; _x} foreach allunits]" is decomposed.

format["%1",{alive _x(0); _x(0); alive _x(1); _x(1); alive _x(2); _x(2)}]

"format ["%1", {alive _x} foreach allunits]" is decomposed.

format["%1",{alive _x(0); alive _x(1); alive _x(2)}]

"{alive _x} foreach allunits" is decomposed.

{alive _x(0); alive _x(1); alive _x(2)}

The result of red returns, respectively.

Edited by Gigan

Share this post


Link to post
Share on other sites
I think that no results are returned because the assignment expression itself is written to the format command.

In order to display a script error, it is good to carry out -showScriptErrors option use.

I had that on, it just would return nothing. As in, nothing... doesn't matter. I was just seeing if I could retrieve an array instead of the last variable in a for each loop without concatenation or pushing arrays.

Share this post


Link to post
Share on other sites

How is the result of having tried this?

in init.sqf

sleep 1;

VARX= {alive _x} foreach allunits; //The third description.

player sidechat format["%1",VARX];

By my test, as for this result, true returns to a value.

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  

×