Page MenuHomeFeedback Tracker

Scripting: forEach-command malfunction.
Closed, ResolvedPublic

Description

In some cases the forEach-command works in an unexpected way. If you want to give a set of variables the same value, you would like to use:

{_x=false} forEach [var1, var2, var3, var4, var5, var6, var7,...]

But you have to use:

var=false; var2=false; var3=false; var4=false; ...
{F18863}

Details

Legacy ID
3104038160
Severity
Tweak
Resolution
Not A Bug
Reproducibility
Always
Category
Scripting
Steps To Reproduce

1.) Open Editor, place a unit if you like.
2.) Open Debug-console by Ctrl+D
3.) Enter Code:
counter=0; denominator="string"; {counter=counter+1} forEach [firsttime, secondtime, thirdtime]; {denominator="text"} forEach [firsttime, secondtime, thirdtime]; {_x="string"} forEach [var1, var2]
4.) In the 'watch-area' fill in the variables, that shall be watched, namely:
counter
denominator
var1
var2
5.) Click on 'LOCAL EXEC'.

6.) Check watched variables. 'var1' and 'var2' didn't get a value.

Advanced:
1.) Change the code from:
{_x="string"} forEach [var1, var2]
to:
{_x=100} forEach [var1, var2]
and click on 'LOCAL EXEC'.
2.) Change the code to:
{_x=false} forEach [var1, var2]
and click on 'LOCAL EXEC'.

Additional Information

This malfunction occurs in debug-console, in triggers and in (sqf-)scripts.

This malfunktion is caused by the command '_x=' and not by the forEach-construction. (See attached *.jpg for further information.)

Event Timeline

IlluminousOne edited Additional Information. (Show Details)
IlluminousOne set Category to Scripting.
IlluminousOne set Reproducibility to Always.
IlluminousOne set Severity to Tweak.
IlluminousOne set Resolution to Not A Bug.
IlluminousOne set Legacy ID to 3104038160.May 7 2016, 1:37 PM

I'm afraid it never worked that way.

{_x=false} forEach [var1, var2, var3, var4, var5, var6, var7,...]

The array doesn't contain variable references, but their values. For engine, it may look like

{_x=false} forEach [true, true, false, true, false, true, true,...]

An you cannot use false=false statement.

The solution is simple. Create an array containing variable names as strings:
{
missionNameSpace setVariable [_x,false];
} forEach ["var1", "var2", "var3", "var4", "var5", "var6", "var7",...]

Mass close.