with: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " <h3 style="display:none">Bottom Section</h3>" to "")
m (Text replacement - " {3,}\|" to " |")
Line 52: Line 52:
};</code>
};</code>
To eliminate possibility of error you can also use [[setVariable]] or [[getVariable]] with desired [[Namespace]], which is also [[Scheduler#Scheduled_Environment|scheduled environment]] safe.
To eliminate possibility of error you can also use [[setVariable]] or [[getVariable]] with desired [[Namespace]], which is also [[Scheduler#Scheduled_Environment|scheduled environment]] safe.


| [[with]] namespace
| [[with]] namespace

Revision as of 19:16, 18 January 2021

Hover & click on the images for description

Description

Description:
Creates a With Type that is used inside a do construct in order to execute code inside a given namespace.
when used in a do-construct in scripts with allowed suspension, an unexpected namespace switch could happen (see note below)

NOTE for the reasons unknown, namespace switching might unexpectedly occur inside some scopes (for, if, try, call) started in scheduled scripts (canSuspend true) after small suspension if with was not the main scope. For example: [] spawn { with uiNamespace do { for "_i" from 1 to 1 do { systemChat str [ currentNamespace isEqualTo uiNamespace, currentNamespace isEqualTo missionNamespace ]; // result [true, false] sleep 0.05; //<-- small suspension systemChat str [ currentNamespace isEqualTo uiNamespace, currentNamespace isEqualTo missionNamespace ]; // result [false, true] <-- switching }; }; }; However if with used in parent scope, everything works correctly: with uiNamespace do { [] spawn { for "_i" from 1 to 1 do { systemChat str [ currentNamespace isEqualTo uiNamespace, currentNamespace isEqualTo missionNamespace ]; // result [true, false] sleep 0.05; //<-- small suspension systemChat str [ currentNamespace isEqualTo uiNamespace, currentNamespace isEqualTo missionNamespace ]; // result [true, false] <-- NO switching }; }; };

To eliminate possibility of error you can also use setVariable or getVariable with desired Namespace, which is also scheduled environment safe.
Groups:
Program Flow

Syntax

Syntax:
with namespace
Parameters:
namespace: Namespace
Return Value:
With Type

Examples

Example 1:
_myWithType = with uiNamespace;
Example 2:
with missionNamespace do {global = global + 1};

Additional Information

See also:
Forward CompatibilitymissionNamespaceuiNamespaceparsingNamespace

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note