with: Difference between revisions
Killzone Kid (talk | contribs) (namespace switching) |
(adapted page by stating with as an operator on it's own) |
||
Line 7: | Line 7: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| | | Creates a [[With Type]] that is used inside a [[do]] construct in order to execute code inside a given namespace. | ||
{{warning | when used in scripts with allowed suspension | {{warning | 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: | '''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: | ||
<code>[] [[spawn]] | <code>[] [[spawn]] | ||
Line 55: | Line 55: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| | | [[with]] namespace |=Syntax | ||
|p1= namespace: [[Namespace]] |= Parameter 1 | |p1= namespace: [[Namespace]] |= Parameter 1 | ||
| [[ | | [[With Type]] |= Return value | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|x1= <code>[[with]] [[missionNamespace]] [[do]] {global = global + 1};</code> |=Example | |x1= <code> _myWithType = [[with]] [[uiNamespace]]; </code> |=Example 1 | ||
|x2= <code>[[with]] [[missionNamespace]] [[do]] {global = global + 1};</code> |=Example 2 | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Revision as of 11:06, 3 January 2017
Description
- Description:
- Creates a With Type that is used inside a do construct in order to execute code inside a given namespace.
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:
To eliminate possibility of error you can also use setVariable or getVariable with desired Namespace, which is also scheduled environment save.[] 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 }; }; };
- Groups:
- Uncategorised
Syntax
Examples
- Example 1:
_myWithType = with uiNamespace;
- Example 2:
with missionNamespace do {global = global + 1};
Additional Information
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