with: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " <dl class="command_description"> <!-- Note Section BEGIN --> <!-- Note Section END --> </dl>" to " ") |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(33 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{RV|type=command | ||
| arma2 | |game1= arma2 | ||
|version1= 1.00 | |||
|game2= arma2oa | |||
|version2= 1.50 | |||
|game3= tkoh | |||
|version3= 1.00 | |||
|game4= arma3 | |||
|version4= 0.50 | |||
|gr1= Program Flow | |gr1= Program Flow | ||
|gr2= Namespaces | |||
| | |descr= Creates a [[With Type]] that is used inside a [[do]] construct in order to execute code inside a given namespace. | ||
{{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 | ||
{{!}}- | |||
{{!}} | |||
<sqf> | |||
0 spawn | |||
{ | { | ||
with uiNamespace do | |||
{ | { | ||
for "_i" from 1 to 1 do | |||
{ | { | ||
systemChat str [ | |||
currentNamespace isEqualTo uiNamespace, | |||
currentNamespace isEqualTo missionNamespace | |||
]; | ]; | ||
// result [true, false] | // result [true, false] | ||
sleep 0.05; // <-- small suspension | |||
systemChat str [ | |||
currentNamespace isEqualTo uiNamespace, | |||
currentNamespace isEqualTo missionNamespace | |||
]; | ]; | ||
// result [false, true] <-- switching | // result [false, true] <-- switching | ||
}; | }; | ||
}; | }; | ||
};</ | }; | ||
</sqf> | |||
< | {{!}} | ||
<sqf> | |||
with uiNamespace do | |||
{ | { | ||
0 spawn | |||
{ | { | ||
for "_i" from 1 to 1 do | |||
{ | { | ||
systemChat str [ | |||
currentNamespace isEqualTo uiNamespace, | |||
currentNamespace isEqualTo missionNamespace | |||
]; | ]; | ||
// result [true, false] | // result [true, false] | ||
sleep 0.05; // <-- small suspension | |||
systemChat str [ | |||
currentNamespace isEqualTo uiNamespace, | |||
currentNamespace isEqualTo missionNamespace | |||
]; | ]; | ||
// result [true, false] <-- NO switching | // result [true, false] <-- NO switching | ||
}; | }; | ||
}; | }; | ||
};</ | }; | ||
</sqf> | |||
{{!}}} | |||
| [[with]] namespace | |s1= [[with]] namespace | ||
|p1= namespace: [[Namespace]] | |p1= namespace: [[Namespace]] | ||
| [[With Type]] | |r1= [[With Type]] | ||
|x1= < | |x1= <sqf>_myWithType = with uiNamespace;</sqf> | ||
| [[ | |x2= <sqf>with missionNamespace do { global = global + 1 };</sqf> | ||
|seealso= [[missionNamespace]] [[uiNamespace]] [[parsingNamespace]] [[currentNamespace]] | |||
}} | }} | ||
{{Note | |||
|user= Hypoxic125 | |||
|timestamp= 20230223070505 | |||
|text= '''Using with:''' | |||
<sqf> | |||
with profileNamespace do { | |||
myVariable = "Hello!"; | |||
}; | |||
</sqf> | |||
'''is the same as:''' | |||
<sqf> | |||
profileNamespace setVariable ["myVariable", "Hello!"]; | |||
</sqf> | |||
This allows you to quickly modify/use variables within a namespace without using '''get/setvariable''' every time. | |||
}} | |||
Latest revision as of 14:58, 26 August 2024
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 Copy0 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 }; }; };Copywith uiNamespace do { 0 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 FlowNamespaces
Syntax
Examples
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