with: Difference between revisions
Jump to navigation
Jump to search
(pre -> code, syntax) |
Killzone Kid (talk | contribs) (described some oddities with using with) |
||
Line 7: | Line 7: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| | | Executes given code inside given [[Namespace|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 used inside them. For example: | |||
<code>[] [[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 | |||
}; | |||
}; | |||
};</code> | |||
However if [[with]] used in parent scope, everything works correctly: | |||
<code>[[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 | |||
}; | |||
}; | |||
};</code> | |||
To eliminate possibility of error you can also use [[setVariable]] or [[getVariable]] with desired [[Namespace]], which is aslo sheduled environment save. | |||
|= Description | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| '''with''' | | '''with''' namespace '''do''' code|= Syntax | ||
|p1= namespace: [[Namespace]] |= Parameter 1 | |p1= namespace: [[Namespace]] |= Parameter 1 | ||
Line 18: | Line 63: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|x1= <code>[[with]] [[missionNamespace]] [[do]] {global = global + 1 | |x1= <code>[[with]] [[missionNamespace]] [[do]] {global = global + 1};</code> |=Example 1 | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Revision as of 17:16, 25 March 2016
Description
- Description:
- Executes given code inside 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 used inside them. 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 aslo sheduled environment save. - Groups:
- Uncategorised
Syntax
Examples
- Example 1:
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