with: Difference between revisions
| Lou Montana (talk | contribs) m (Text replacement - ";[ 	]+ " to "; ") | Lou Montana (talk | contribs)  m (Some wiki formatting) | ||
| Line 15: | Line 15: | ||
| |gr1= Program Flow | |gr1= Program Flow | ||
| |descr= Creates a [[With Type]] that is used inside a [[do]] construct in order to execute code inside a given namespace.   | |descr= Creates a [[With Type]] that is used inside a [[do]] construct in order to execute code inside a given namespace. | ||
| {{Feature |  | {{Feature|important|To avoid the below-mentioned issue error (whether in [[Scheduler#Scheduled Environment|scheduled]] or [[Scheduler#Unscheduled Environment|unscheduled]] environment) use [[setVariable]]/[[getVariable]] with the desired [[Namespace]].}} | ||
| |pr= When used in a do-construct in scripts with allowed suspension, a namespace switching might unexpectedly occur inside some scopes ([[for]], [[if]], [[try]], [[call]]) started in a [[Scheduler#Scheduled Environment|scheduled]] environment after small suspension if [[with]] was not the main scope; however, the issue does not arise if [[with]] is used in the parent scope: | |||
| {{{!}} class="wikitable" | |||
| ! namespace switch risk | |||
| ! namespace switch safe | |||
| {{!}}- | |||
| {{!}} | |||
| <code>[] [[spawn]] | <code>[] [[spawn]] | ||
| { | { | ||
| 	[[with]] [[uiNamespace]] do   | 	[[with]] [[uiNamespace]] [[do]] | ||
| 	{ | 	{ | ||
| 		[[for]] "_i" [[from]] 1 [[to]] 1 [[do]]   | 		[[for]] "_i" [[from]] 1 [[to]] 1 [[do]]   | ||
| Line 28: | Line 34: | ||
| 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | ||
| 			]; | 			]; | ||
| 			{{cc|result [true, false]}} | |||
| 			[[sleep]] 0.05;  | 			[[sleep]] 0.05; {{cc|<-- small suspension}} | ||
| 			[[systemChat]] [[str]] [ | 			[[systemChat]] [[str]] [ | ||
| 				[[currentNamespace]] [[isEqualTo]] [[uiNamespace]],   | 				[[currentNamespace]] [[isEqualTo]] [[uiNamespace]],   | ||
| 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | ||
| 			]; | 			]; | ||
| 			{{cc|result [false, true] <-- switching}} | |||
| 		}; | 		}; | ||
| 	}; | 	}; | ||
| };</code> | };</code> | ||
| {{!}} | |||
| <code>[[with]] [[uiNamespace]] do | <code>[[with]] [[uiNamespace]] [[do]] | ||
| { | { | ||
| 	[] [[spawn]]   | 	[] [[spawn]] | ||
| 	{ | 	{ | ||
| 		[[for]] "_i" [[from]] 1 [[to]] 1 [[do]]   | 		[[for]] "_i" [[from]] 1 [[to]] 1 [[do]]   | ||
| Line 49: | Line 55: | ||
| 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | ||
| 			]; | 			]; | ||
| 			{{cc|result [true, false]}} | |||
| 			[[sleep]] 0.05;  | 			[[sleep]] 0.05; {{cc|<-- small suspension}} | ||
| 			[[systemChat]] [[str]] [ | 			[[systemChat]] [[str]] [ | ||
| 				[[currentNamespace]] [[isEqualTo]] [[uiNamespace]],   | 				[[currentNamespace]] [[isEqualTo]] [[uiNamespace]],   | ||
| 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | 				[[currentNamespace]] [[isEqualTo]] [[missionNamespace]] | ||
| 			]; | 			]; | ||
| 			{{cc|result [true, false] <-- NO switching}} | |||
| 		}; | 		}; | ||
| 	}; | 	}; | ||
| };</code> | };</code> | ||
| {{!}}} | |||
| |s1= [[with]] namespace | |s1= [[with]] namespace | ||
| Line 68: | Line 74: | ||
| |x1= <code>_myWithType = [[with]] [[uiNamespace]];</code> | |x1= <code>_myWithType = [[with]] [[uiNamespace]];</code> | ||
| |x2= <code>[[with]] [[missionNamespace]] [[do]] {global = global + 1};</code> | |x2= <code>[[with]] [[missionNamespace]] [[do]] {global = global + 1};</code> | ||
| |seealso=  | |seealso= [[missionNamespace]], [[uiNamespace]], [[parsingNamespace]], [[currentNamespace]] | ||
| }} | }} | ||
Revision as of 20:36, 23 August 2021
Description
- Description:
- Creates a With Type that is used inside a do construct in order to execute code inside a given namespace.
- Problems:
- When used in a do-construct in scripts with allowed suspension, a namespace switching might unexpectedly occur inside some scopes (for, if, try, call) started in a scheduled environment after small suspension if with was not the main scope; however, the issue does not arise if with is used in the parent scope:
namespace switch risk namespace switch safe [] 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 }; }; };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:
- Program Flow
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
 
	


